使用jquery

时间:2016-03-12 19:42:51

标签: javascript php jquery subtitle

我写了一个jquery脚本来播放带有随机音频片段+附加字幕的短视频片段。有关“工作”的信息,请参阅here。例。大部分代码在视频结束时触发,而且该部分运行良好。但是我在on document.ready函数上偶尔遇到问题。它大约8次中的7次,但有时为.vtt字幕文件提供404,第一个视频没有字幕播放(我检查了链接,实际创建了.vtt文件)。 (您可以通过刷新页面几次来重新创建错误)我想知道是否有人建议如何修复或调试此...谢谢!

$(document).ready(function() {
        createsubtitle(); //creates random subtitle string
        timestamp0 = $.now();// two timestamps to make unique files (to be deleted afterwards)
        timestamp1 = $.now();
        window.timestamp0 = timestamp0
        window.timestamp1 = timestamp1
        $.ajax({type: "POST",url:"save1.php",data: {text:subtitle, time:timestamp1},success: function() {console.log("message sent!")}}); // first .vtt file is made using php (see code below)
        createsubtitle(); // new random subtitle
        $.ajax({type: "POST",url:"save0.php",data: {text:subtitle, time:timestamp0},success: function() {console.log("message sent!")}}); //  second php (the script alternates between two .vtt files)
        $("#subtitles").attr("src", "subtitle/sub1" + timestamp1 + ".vtt"); // one .vtt file is added as src to track element #subtitles
        $('#rearrangements').get(0).play(); // video is played
});

php代码:

#!/usr/bin/php
<?php
$subtitle = $_POST['text'];
$timestamp = $_POST['time'];
$filename = 'subtitle/sub1'.$timestamp.'.vtt';
$myfile = fopen($filename, "w") or die("Unable to open file!");
$txt = $subtitle;
fwrite($myfile, $txt);
fclose($myfile);
?>

0 个答案:

没有答案