admin管理员组文章数量:1192136
Hi I have an application which has a grid and a js video player. Currently I am populating the grid with data from a SQL database, I have a function call when ever a row is clicked which calls a stored procedure and returns a url i then use that url to change the source change the source. The funny thing is with a basic html 5 video player the code i have works fine but doesn't work for Video JS
My code -
function changesource(url) {
var video = $("#vid1");
video.src = url;
document.getElementById('vid1').src = url;
}
// calls the function for browse
function getBrowseData() {
$.ajax({
type: "post",
data: JSON.stringify({
archive_header_Key: testdata,
}),
url: "/Search.aspx/GetBrowseData",
dataType: "json",
contentType: "application/json",
success: function (object) {
response(object);
},
complete: function (object) {
},
error: function (object) {
}
});
function response(object) {
var obj = (object.d[0]["browse_file"]);
var slashReplace = obj.replace(/\\/g, "/");
var slashFinal = slashReplace.substring(10);
var browsevalue = GetValue("BrowseServer");
var slashfinal = "http://" + browsevalue + ":5060" + slashFinal;
Location = slashfinal;
$('#p1').text(slashfinal);
changesource(slashfinal);
}
}
var Video = ("<video id='vid1' class='video-js vjs-default-skin' controls preload='none' width='640' height='264' data-setup='{}'><source src=" + Location + " type='video/mp4'/></video> <script>var options = { hidden: false }, mplayer = videojs('vid1'); mplayer.rangeslider(options); mplayer.showSlider();</script>");
Any help would be appreciated
Hi I have an application which has a grid and a js video player. Currently I am populating the grid with data from a SQL database, I have a function call when ever a row is clicked which calls a stored procedure and returns a url i then use that url to change the source change the source. The funny thing is with a basic html 5 video player the code i have works fine but doesn't work for Video JS
My code -
function changesource(url) {
var video = $("#vid1");
video.src = url;
document.getElementById('vid1').src = url;
}
// calls the function for browse
function getBrowseData() {
$.ajax({
type: "post",
data: JSON.stringify({
archive_header_Key: testdata,
}),
url: "/Search.aspx/GetBrowseData",
dataType: "json",
contentType: "application/json",
success: function (object) {
response(object);
},
complete: function (object) {
},
error: function (object) {
}
});
function response(object) {
var obj = (object.d[0]["browse_file"]);
var slashReplace = obj.replace(/\\/g, "/");
var slashFinal = slashReplace.substring(10);
var browsevalue = GetValue("BrowseServer");
var slashfinal = "http://" + browsevalue + ":5060" + slashFinal;
Location = slashfinal;
$('#p1').text(slashfinal);
changesource(slashfinal);
}
}
var Video = ("<video id='vid1' class='video-js vjs-default-skin' controls preload='none' width='640' height='264' data-setup='{}'><source src=" + Location + " type='video/mp4'/></video> <script>var options = { hidden: false }, mplayer = videojs('vid1'); mplayer.rangeslider(options); mplayer.showSlider();</script>");
Any help would be appreciated
Share Improve this question edited Feb 2, 2016 at 11:30 Mark Moonie Griffiths asked Feb 2, 2016 at 11:05 Mark Moonie GriffithsMark Moonie Griffiths 2352 gold badges4 silver badges15 bronze badges2 Answers
Reset to default 23If you're using video.js you need to use its API to set the source. The HTML5 video API does not work as once the video.js player is initialised the element with the id vid
is not a video element.
var video = videojs("vid1");
video.src(url);
Video.js will infer the type of video for a few file extensions, but it's better to include the type:
video.src({
type: 'video/mp4',
src: 'https://example.com/myvideo.mp4'
});
if you are using react functional component with video js , then you have to access the video tag by using useRef Hook, like this
{
import {useRef} from 'react';
const videoRef=useRef();
useEffect(()=>{
videoRef.current.src=DYNAMIC_DATA_URL
})
return <>
<video
id={state.video.id}
className="video-js vjs-big-play-centered"
width="800"
height="482"
controls
autoPlay={true}
preload="auto"
poster={state.video.thumb}
data-setup="{}"
ref={videoRef}
>
<source src={a} type="video/mp4"></source>
</video>
</>
}
本文标签: javascriptVideo Js loading source dynamicallyStack Overflow
版权声明:本文标题:javascript - Video Js loading source dynamically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738451223a2087496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论