我正在浏览器窗口中进行视频播放,视频源和音频源是从后端数据服务器检索的。播放工作正常,并且在开始播放时以及暂停并重新启动时处于同步状态。我遇到的问题是将控件拖回视频时。它不会自动返回到特定帧。有没有办法在javascript中控制它?
另一个问题是视频控件指示音频的播放。这意味着如果您播放视频,音频会开始,反之亦然。只是在寻找有关如何处理此类问题的建议。
var vid = document.getElementById("wVideo");
var aud = document.getElementById("wAudio");
var playbackURL = "not yet set";
var selectedID;
var selectedType;
vid.onplay = function() {
try {
aud.play();
} catch (e) {
console.log("Error on PlaySelectedCall: " + e.message + ".(punt)");
}
}
vid.onpause = function() {
try {
aud.pause();
} catch (err) {
console.log("Error on pause: " + err.message);
}
}
vid.onseeking = function() {
if (vid.currentTime == 0) {
aud.currentTime = 0;
aud.pause();
}
}
function exportVideo() {
var exportScreenURL = "/myplayer/exportSaveCall.action?type=screen";
var frame = document.getElementById("playScreenFrameII");
frame.src = exportScreenURL;
}
function playScreen() {
var playScreenForm = document.getElementById('playScreenForm');
playScreenForm.action = "/myplayer/exportSaveCall.action?type=screen";
document.getElementById('callID').value = getSelectedID();
playScreenForm.submit();
hide();
}
function showButtonOnStart() {
var x = document.getElementById('buttonLink');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.visibility = 'hidden';
}
}
function getAudioTicket() {
showButtonOnStart();
selectedID = getSelectedID();
console.log("selectedID is " + selectedID);
if (selectedID == null) {
return;
}
$.ajax({
url: "/myplayer/getAudio.action",
type: "GET",
data: {
ID: selectedID
},
success: function(result, status, responseText) {
var data = $.parseJSON(result);
try {
playbackURL = data.playbackURL;
if (playbackURL != null) {
console.log("Audio url is " + playbackURL);
aud.setAttribute("src", playbackURL);
aud.preload = "auto";
} else {
console.log("No audio found for this");
aud.style.visibility = "hidden";
}
} catch (err) {
writeAjaxError("setupTicketedPlaybackURL()", err.message);
}
},
error: function(request, textStatus, errorThrown) {
writeAjaxError("ScreenplayerWMP
setupTicketedPlaybackURL()
",errorThrown);
}
});
}
<body style="width:100%; height:100%; background:buttonface;" bottommargin="0" id="body" language="javascript" onload="getAudio();" leftmargin="0" rightmargin="0" topmargin="0">
<!-- Media Player -->
<div>
<center>
<video width="100%" height="90%" id="wVideo" controls controlsList="nodownload" preload="auto" autoplay>
<source src="${playbackURL}" type="video/webm">
Your browser does not support the video tag.
</video>
<audio controls id="wAudio" controls controlsList="nodownload
noremoteplayback" preload="auto" autoplay>
<source src="" type="audio/wav" >
Your browser does not support the audio element.
</audio>
</center>
</div>
您可以
尝试在audio
和video
元素上侦听timeupdate
事件,当currentTime
发生变化时,该事件会更新,这可能会使同步更容易。我还没有尝试过,但它可能会有所帮助。