我已尝试搜索解决方案,但我在尝试确定要搜索的内容时遇到问题。我正在尝试使用AJAX来获取PHP Get请求,它似乎正在提交(就像离开页面一样)。
我正在使用BitMovin库,这似乎是个问题。该代码适用于启动直播,但AJAX没有。当我注释掉它的BitMovin代码时,AJAX可以工作。
当运行请求并取消注释BitMovin代码时会发生什么,它会打开此页面(假设在后台完成请求):
{ "data": { "success" : true, "message" : "Success!" } }
剧本:
<?php
use bitcodin\AwsRegion;
use bitcodin\Bitcodin;
use bitcodin\VideoStreamConfig;
use bitcodin\AudioStreamConfig;
use bitcodin\Job;
use bitcodin\JobConfig;
use bitcodin\Input;
use bitcodin\S3InputConfig;
use bitcodin\EncodingProfile;
use bitcodin\EncodingProfileConfig;
use bitcodin\ManifestTypes;
use bitcodin\Output;
use bitcodin\S3OutputConfig;
use bitcodin\GcsOutputConfig;
use bitcodin\HttpInputConfig;
use bitcodin\LiveStream;
require_once './vendor/autoload.php';
//more code for my site
if (!empty($errors)) {
$data['success'] = false;
$data['errors'] = $errors;
}else{
Bitcodin::setApiToken('---my-key-removed-for-post---');
$encodingProfileConfig = new EncodingProfileConfig();
$encodingProfileConfig->name = 'Encoding Name';
$low = new VideoStreamConfig();
$low->bitrate = 1000000;
$low->height = 480;
$low->width = 854;
$encodingProfileConfig->videoStreamConfigs[] = $low;
$audio = new AudioStreamConfig();
$audio->bitrate = 128000;
$encodingProfileConfig->audioStreamConfigs[] = $audio;
$encodingProfile = EncodingProfile::create($encodingProfileConfig);
$outputConfig = new S3OutputConfig();
$outputConfig->name = "OutputName";
$outputConfig->accessKey = "--removed-for-post---";
$outputConfig->secretKey = "--removed-for-post---";
$outputConfig->bucket = "bucketName";
$outputConfig->region = AwsRegion::US_WEST_2;
$outputConfig->prefix = 'folder/test';
$outputConfig->makePublic = false;
$output = Output::create($outputConfig);
$liveInstance = LiveStream::create('StreamName', 'StreamKey', $encodingProfile, $output, 0);
while($liveInstance->status != $liveInstance::STATUS_RUNNING)
{
sleep(2);
$liveInstance->update();
if($liveInstance->status == $liveInstance::STATUS_ERROR)
{
$errors['bitmovin'] = 'Error with bitmovin';
$data['errors'] = $errors;
//throw new \Exception("Error occurred during Live stream creation");
}
}
$rtmpUrl = "";
$rtmpUrl = $liveInstance->rtmpPushUrl;
$streamInstanceId = $liveInstance->id;
$data['success'] = true;
$data['message'] = 'Success!';
}
echo json_encode($data);
?>
这是AJAX代码。
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#start").click(function(event){
var formData = {};
$.ajax({
type : 'GET',
url : './foobar.php',
data : formData,
dataType : 'json',
encode : true
}).done(function(data) {
console.log(data);
});
event.preventDefault();
});
});
</script>
</head>
<body>
<p><a href="#" id="start">Start</a></p>
</body>
</html>
所以我知道它是BitMovin代码,为什么要在新页面中打开代码?
提前致谢。
答案 0 :(得分:0)
正如我们的支持对话中已经澄清的那样,该问题似乎与bitcodin-php API Client无关。
仅供参考:不必为每个直播流创建新的编码配置文件。您可以使用现有的EncodingProfile::get(<yourEncodingProfileId>)
。有关API客户端的更多信息,请访问https://bitmovin.com/encoding-documentation/encoding-api/
最佳, 的Gernot