Showing posts with label html5-video. Show all posts
Showing posts with label html5-video. Show all posts

Monday, February 19, 2018

render video stream as partial content rather than full stream to chrome

Leave a Comment

We currently submit a video playback request to back end server the sends the full stream as inputstream to be played back in the browser(window). This works fine but has an added complication in that the seek function does not work in chrome. The suggested solution is to tell the webserver that it needs to accept a byte range and then deliver the stream in partial byte ranges. I am not sure if this will resolve the situation but my question is how to return the stream in byte ranges considering the following is the way it is done now:

    InputStream is= null;     is = new FileInputStream(ndirectoryFile);      ....     //(calling class request)     stream = videoWrapper.getVideo(id, address); 

If I read the file in byte ranges, do I just loop through the file but how do I send the response:

InputStream is = new ByteArrayInputStream(new byte[] { 0, 1, 2 });  ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[1024]; while ((nRead = is.read(data, 0, data.length)) != -1) {     buffer.write(data, 0, nRead); }  buffer.flush(); byte[] byteArray = buffer.toByteArray( 

The initial inputstream gets passed to quite a few classes along the way prior to sending the final response. Any ideas please.

EDIT:

I would like to just understand the html5 video issue with chrome. There are quite a few posts on setting the server response headers to include Accept-Ranges=, Content-length= , Content-Range= and this would tell chrome to download the byte range which will then allow seek feature to work. As the video playback seek works in firefox I should not have to change how I deliver the stream or would I? Would I still have to submit partial ranges of the video from the server? and how?

1 Answers

Answers 1

I resolved my situation by not having to change any streaming code but rather just ensure the correct range headers were applied to the response to ensure chrome handled the playback.

Accept-Ranges: bytes Content-Range: bytes 0-1025/905357 Content-Length: 905357 
Read More

Sunday, December 31, 2017

HTML5 Video - Get final src URL destination

Leave a Comment

I'm displaying video content from a 3rd party service on my website:

<video src="http://www.example.com/api/v1/media/video.mp4?status=true"></video> 

The service detects the user's geo-location and browser's language and returns video that fit those parameters.

http://www.example.com/api/v1/media/video.mp4?status=true REDIRECT TO http://www.example.com/api/v1/media/US/EN/English_CAT.mp4 

Other than the media URL, the service doesn't provide the actual file name that particular user received.

How can I fetch the final media path/name? Tried multiple ways but iframes blocked by X-Frame-Options: DENY and AJAX blocked as well.

1 Answers

Answers 1

The short answer is you probably can't do this all on the client-side. You will run into same-origin issues. In addition, it is not possible to directly get the HTTP headers of a <video> element.

If the service provider for the videos enables CORS support you may be able to get the final URL via a workaround. Even with CORS enabled you won't be able to get the HTTP headers or final URL of the video from the <video> element.

You can work around this by:

  1. Make a 2nd HTTP request (XMLHttpRequest, fetch, $.ajax, etc) to the same URL.
  2. Make a HEAD request instead of a GET request. GET requests will attempt to retrieve the entire file. HEAD requests do not download the body, only the headers, which would be enough for resolving the redirect.
  3. Look in the headers of the HEAD response for the final URL path.

Here is an example that uses fetch:

var request = new Request(yourVideoUrl); request.mode = 'cors'; request.method = 'HEAD';  fetch(request) .then(function(res){   console.log(res.url); // This should be the final URL }); 
Read More

Monday, September 11, 2017

Android WebView Video after closing fullscreen view, webview auto scrolls

Leave a Comment

I am using WebView to display a webpage having text as well as video content.

It loads & display video correctly as expected.

But when I go to full screen view of video ( I implemeted full screen video view as given here ) and then come back to WebView, WebView autoscroll in some amount.

How can I fix that?

Please suggest some idea/link.

0 Answers

Read More

Saturday, August 5, 2017

Chromecast not playing multiple HTML5 videos

Leave a Comment

I have 2 video players on single page. On desktop, everything works fine, both video players are playing videos. But when I try to cast this page to Chromecast (via Google Chrome extension or via https://demille.github.io/url-cast-receiver/), only first video player is active and playing, second video player is not working.

I tried to debug it and it looks like second video ends at video readyState=1 (first video has readyState=4)

Is there way to fix this? (I need multiple video players on single page, so using only one player and switching video files URLs is not a solution)

URL: http://iuvomedia.eu/chromecast/

2 Answers

Answers 1

If you want one video to play and other to be pre-loaded then you should make a queue of videos you want to play. Chromecast will play single video at a time and when it ends it'll automatically load the next one in the queue.

For information on autoplay and queuing you may visit https://developers.google.com/cast/docs/autoplay

Answers 2

You cannot have more than one active media element.

I mean, you can have two media elements where one plays a video that doesn't have any audio and the second one plays only audio.

You cannot have two active video or two active audio pipelines at the same time.

check here: Create multiple instances of html video object

Read More

Friday, May 5, 2017

HTML5 video - setting video.currentTime breaks the player

Leave a Comment

I am trying to interact with a 3rd-party html5 video player in Chrome. I am able to obtain a valid reference to it thusly:

document.getElementsByTagName("video")[1] 

...and the readyState is 4, so it's all good.

I can successfully (and with expected result) call:

document.getElementsByTagName("video")[1].play(); document.getElementsByTagName("video")[1].pause(); 

BUT when I call:

document.getElementsByTagName("video")[1].currentTime = 500; 

...the video freezes and it doesn't advance to the new currentTime. The video duration is much longer than 500 seconds, so it should be able to advance to that spot. I have tried other times besides 500, all with same result. If I examine currentTime, it is correct as to what I just set. But it doesn't actually go there. Also I can no longer interact with the video. It ignores any calls to play() or pause() after I try to set currentTime.

Before I call currentTime, when I call play() I get this valid promise back, and everything else still works: enter image description here

After I call currentTime, when I call play(), I get this broken promise back, and now nothing works on that video object:enter image description here

If you have a Hulu account you can easily observe this behavior on any video by simply trying it in the Chrome developer console.

3 Answers

Answers 1

Try below code, it will first pause then set your position then again play

document.getElementsByTagName("video")[1].pause(); document.getElementsByTagName("video")[1].currentTime = 500; document.getElementsByTagName("video")[1].play(); 

Answers 2

Why don't you try this code.

function setTime(tValue) {         //  if no video is loaded, this throws an exception              try {                 if (tValue == 0) {                     video.currentTime = tValue;                 }                 else {                     video.currentTime += tValue;                 }               } catch (err) {                  // errMessage(err) // show exception              errMessage("Video content might not be loaded");                }      } 

Answers 3

    var myVideo=document.getElementsByTagName("video")     if(myVideo[1] != undefind)         {              myVideo[1].currentTime=500;        }    /* or provide id to each video tag and use getElementById('id')    */     var myVideo=document.getElementById("videoId")     if(myVideo != undefind)         {              myVideo.currentTime=500;        } 
Read More

Wednesday, May 3, 2017

html5 a download attribute doesn't work when the url is a blob url

Leave a Comment

We're creating a chrome extension to download videos, currently I have this function :

function downloadvideo(video) {     const url = URL.createObjectURL(video.captureStream());     const aelem = document.createElement('a');     document.body.appendChild(aelem);     aelem.setAttribute("href",url);     aelem.setAttribute("download","video.mp4");     aelem.click();     //URL.revokeObjectURL(url); } 

Here video parameter is a html5 video element, I'm using caputreStream because some websites(notably youtube) uses blob url which are revoked apparently So I create a new Blob url from MediaStream.

The function above is executed as part of video's onloadeddata event.

The dialog is shown and the filename is correct but when I click "Save" chrome says "failed : could not find the file".

So how to make it actually work ?

By the way I tried to do ajax against url but chrome refuses with the message : "Cross-origin is only supported for schemes http,https,chrome,chrome-extension" :3 .

2 Answers

Answers 1

Here is is function which i used to download video in bloburl which i stored from canvas frame capture

function createdVideo(){         var output = 'your video or captured stream or canvas capture'           var url = webkitURL.createObjectURL(output);         // output_video.src = url; //toString converts it to a URL via Object URLs, falling back to DataURL         download.href = url;//download is id of download link which als ohave download atribute} 

i Hope will work in your case

Answers 2

I am noobie but it worked for me , <a href="#" download> this helps me downloading every kind of file associated with it 'href'

Read More

Tuesday, April 12, 2016

Calculate .m4s segment file suffix in HTML5 video streaming when user seek to another time

Leave a Comment

I have created segments of 10 Sec for a long mp4 video using Mp4Box. The Mp4Box creates a meta info file mv_init.mp4 and and segments like mv_1.m4s, mv_2.m4s... Now i stream it using HTML5 Media Source Extension. The streaming is working properly.

But the problem is that I am unable to utilize TIME SEEKING feature of HTML5 player. When a user seek through the seekbar and switch to another time then I need to fetch the correct segment file (mv_{number}.m4s) for that currentTime. Currently I calculate the segment file suffix using the following technique:

Example:-

Video Duration: 2 Hour

Segment Size: 10 Sec

Let say the user seeked to time 25 Min, so in this case I load the following segment file:

25 Min = 25 *60 = 1500 Seconds As each segment is of 10 Sec So I divide 1500 by 10 = 1500 / 10 = 150

Segment File = mv_150.m4s

The calculation apparently seems correct but the HTML5 player then downloads many more files after mv_150.m4s to continue with the streaming.

Can anyone guide me in this case of how to correctly calculate segment file number so that after seeking the streaming run smoothly without downloading any extra files.

I used the following command to created Segments of Mp4 video:

MP4Box -dash 10000 -out video.mpd -dash-profile live -segment-name mv_ -rap video.mp4

0 Answers

Read More