VideoJS: not working on IOS - javascript

I used the videojs and it is working fine all browsers(including IE) and on Android . But it is not working on IOS devices (iphone and ipad IOS version 6).
Here is the code which I am using to add the video to the page.
<video id="video1" class="video-js vjs-default-skin" width="276" height="153" controls="" preload="auto" data-setup="{}">
<source src=myvideo.mp4 type="video/m4v" >
</video>
I have spent ages and could not find any solution.
I m using video.js Version 3.2.0 and getting the loading spinner forever.
I tried using version 4 and just black screen comes up.
Any Help please.

First put double quotes around the source src attribute and try that. If that doesn't solve it, it sounds like the problem is with the mp4 itself, most likely because of the way it's been encoded or it has a huge filesize. Try using videojs's default movie (http://vjs.zencdn.net/v/oceans.mp4) and see if that works. If it works, you know the problem lies with the movie file itself.

Your web server should support byte-range requests,check whether web server support 206 response. If you are using nginx,add mp4 module.

I solved most of my mp4 encoding issues using handbrake.

Try to change type="video/m4v" to "video/mp4".
<video class="video-js">
<source src="//vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
<source src="//vjs.zencdn.net/v/oceans.webm" type="video/webm">
</video>
Offical docs.

Related

Video.js not working on iOS Safari, Chrome etc [duplicate]

I have some kind of a strange problem. I try to create a website with a looped background video. The code looks like this one:
<video src="video/bg.mp4" style="z-index: -1;object-fit: cover;" poster="video/bg.jpg" autobuffer autoplay loop muted></video>
This works perfectly fine on most browsers (IE struggles with this object-fit thing but I don't mind) but on iPhone the video won't autoplay but on iPad it does. I already read the New Policies for iOS and I think I meet the requirements (otherwise iPad won't autoplay). I did some other testing:
Removing overlaying divs won't fix it
Removing z-index won't fix it
Wifi or Cellular doesn't make a difference
Video filesize doesn't make a difference, too
Am I doing it wrong or does iPhone simply won't autoplay videos and always requires interaction? I only care for iOS 10, I know that the requirements were different on iOS 9
Does playsinline attribute help?
Here's what I have:
<video autoplay loop muted playsinline class="video-background ">
<source src="videos/intro-video3.mp4" type="video/mp4">
</video>
See the comment on playsinline here: https://webkit.org/blog/6784/new-video-policies-for-ios/
iOs 10+ allow video autoplay inline. but you have to turn off "Low power mode" on your iPhone.
Here is the little hack to overcome all the struggles you have for video autoplay in a website:
Check video is playing or not.
Trigger video play on event like body click or touch.
Note: Some browsers don't let videos to autoplay unless the user interacts with the device.
So scripts to check whether video is playing is:
Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
get: function () {
return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
}});
And then you can simply autoplay the video by attaching event listeners to the body:
$('body').on('click touchstart', function () {
const videoElement = document.getElementById('home_video');
if (videoElement.playing) {
// video is already playing so do nothing
}
else {
// video is not playing
// so play video now
videoElement.play();
}
});
Note: autoplay attribute is very basic which needs to be added to the video tag already other than these scripts.
You can see the working example with code here at this link:
How to autoplay video when the device is in low power mode / data saving mode / safari browser issue
I had a similar problem and I tried multiple solution. I solved it implementing 2 considerations.
Using dangerouslySetInnerHtml to embed the <video> code. For example:
<div dangerouslySetInnerHTML={{ __html: `
<video class="video-js" playsinline autoplay loop muted>
<source src="../video_path.mp4" type="video/mp4"/>
</video>`}}
/>
Resizing the video weight. I noticed my iPhone does not autoplay videos over 3 megabytes. So I used an online compressor tool (https://www.mp4compress.com/) to go from 4mb to less than 500kb
Also, thanks to #boltcoder for his guide: Autoplay muted HTML5 video using React on mobile (Safari / iOS 10+)
I had the same problem - the video not play on iOS. I tried all the code options "playsinline autoplay loop muted". The problem was the video I received was in the wrong mp4 codec. So what helped us, was to upload the video to Vimeo and download the HD Version again. The video is now playing on all mobile devices.
You could also try to use mpeg streamclip. Here is a screenclip of VLC - those are the correct settings. Hope someone does not have to spend 2 hours searching for the problem - happy holidays
Here is a simple solution to auto-play the video in IOS, I've already tried and it is perfectly working on IOS, Android, also on all the browsers on various platforms.
simply use (data-wf-ignore) and (data-object-fit) Attributes for the video and data-wf-ignore for the source tag..
You can see the working example with code here at this Snippet:
<video id="myVideo" autoplay="" muted="" playsinline="" data-wf-ignore="true" data-object-fit="cover">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" data-wf-ignore="true" />
</video>

How to play an .m4a file in the browser? (React/HTML5)

I'm building a website that queries the iTunes API, and in the browser I need to be able to play the 30-second song previews associated with each song in the API (which are in .m4a format)
I've tried playing the file in both of the following ways, but neither worked:
<audio controls="controls">
<source src={track1} type="audio/m4a" />
</audio>
<video width="320" height="240">
<source src={track1} type="video/mp4">
</source>
</video>
When I tried using the audio tag, a media player appeared on the page, but it didn't actually load the file.
I've been researching this for a couple of hours but I haven't been able to find a way of accomplishing this (it doesn't seem like it should be this hard). Does anyone have any ideas of how I might make get this working? Thanks very much
Did you check the path of your sound files is correct? I was having this same issue on a React project.
Check the network tab in Dev tools to see what the status code is for your sound file resource. If it's 206 then it's most likely a file path issue:

HTML5 video tag doesn't work on mobile

I have TV video stream (which is apparently mpeg-ts stream), if I use html5 video tags it all works find on win/mac machines using Chrome.
<video id="player1" width="640" height="360" preload="none" controls playsinline webkit-playsinline>
<source src=""http://192.168.1.72:9981/stream/channelid/2013555866?ticket=388550710ddf21ad5c6ffd61fcd3d0dc24cf46d2&profile=matroska type="video/webm">
</video>
But that doesn't work on Android tablet nor on iOS.
I have tried installing multiple different JS player, such as mediaelement, plyr, video.js, mpegts... And I have installed like all three browsers on Android tablet - Chrome, Opera and Mozilla for testings. Every single JS player works fine if I watch the video from my laptop (Chrome), but none of them works when I access from Android device.
The furthest I can get is using Opera+plyr(or video.js) to get an audio playing fine, but with a black screen, no video.
add this as your video starting tag and it will autoplay for android and safari mobile :
<video autoplay="" muted="" loop="" playsinline="" id="vid" preload="auto" width="100%" height="100%">
you also need mp4, ogv and webm formats for crossbrowser
This might work for you. It works fine for me.
<video autoplay="autoplay" loop="loop" muted defaultMuted playsinline>
I would try enabling controls as on iOS if your video is supposed to start automatically it will not allow it.
Another thing is to try adding an HTTP Range Header, it helps to split video into byte ranges which is something to take into mind with mobile. This is more for iOS in general but take a look at this link: http://fdiv.net/2013/05/17/getting-html5-video-work-ios-mobile-safari
Also as mentioned by other check the format of your video you should ALWAYS have multiple types available.
Video tag doesn't work on mobile. What I've seen people do lately is use gif's as the poster of the video on mobile. I would also look into tools like Wistia for extra video support. Gifs work on mobile, but as the video assets, they take a while to load since they're usually big.
I don't recommend self-hosting as you won't have a ton of support such as slowly loading the video or dynamically switch from 320p version to HD version as it loads, etc.
For example https://wistia.com/learn/marketing/boost-engagement-with-gifs
If you're using a separate host for your files, its server should have a valid SSL certification like my case. My android video player did not work until I added a certification.

HTML5 Video not rendering on Safari & Firefox with Angular.js

Im trying to display some static HTML5 video in my Angular app. It plays without issues in Chrome but not on Safari or Firefox.
<video class="masthead-video w100 m-w100" autoplay loop muted>
<source src="public/img/test.mp4" type="video/mp4">
<source src="public/img/test.webm" type="video/webm">
<source src="public/img/test.ogv" type="video/ogg">
Your browser does not support the video tag.
</video>
Loading this markup into a browser as simple HTML (no angular or any other markup) allows it to play on Safari and Firefox normally without issues.
Ive tried using ng-src instead (even though I shouldnt have to since Im not using dynamic paths) but it didnt help.
Does anyone know of any issues when using HTML5 video with Angular.js?
Use $sce for trust source url .
$scope.trustSrc = function (src) {
return $sce.trustAsResourceUrl(src);
};
$scope.src= public/img/test.mp4;
Html Content
<video class="masthead-video w100 m-w100" autoplay loop muted>
<source ng-src="{{trustSrc(src)}}" type="video/mp4">
Your browser does not support the video tag.
</video>
appy this way for your code.

mediaelement js says that webm file is damaged and can not be played

I'm having a problem with mediaelement js and webm files in FF. I have converted a mp4 vide into a webm file, and made it available on my server. I'm using the code below.
<video width="320" id="player1" height="240" controls="controls">
<source type="video/webm" src="somefile.webm" />
<source type="video/ogg" src="somefile.ogv" />
<source type="video/mp4" src="somefile.mp4" />
<-- there is also a flash fallback which is working fine in FF, but I've removed it here to simplify the example -->
</video>
This works fine in all browsers except Firefox. It tells me that the file is damaged and can not be played. But, if i open firebug and open the webm-file by selecting "Open in new tab" - the video is loaded from my server and played correctly - in Firefox.
Is there anyone else who has come across the same problem and knows a solution to it? I've been searching, but i seem only to find answers saying that the file doesn't have the correct mime-type. I don't think that's the problem in my situation, since it plays very well in FF when i open it in a new tab, and not playing through mediaelement js.
Edit: The response headers in firefox, for the file that is "damaged" says "Content-Type video/webm"
Seems like the server did not set the correct Content-Type after all. I got it fixed, and now it works like a charm.

Categories

Resources