I am loading an html file to my webview using [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"faq" ofType:#"html"] isDirectory:NO]]]; Now I want to embed a youtube video into the html file. I have the file but don't know what to add in order for it to work. I have found code that let's you load it as a string but what I need is to load it inside the html file. I have tried adding, with a few fixes, the same code that I have found on other posts to the html file, but it always comes up as an external link, instead of embedded inside the html file. Here is what I have:
<script type="text/javascript" src="http://www.youtube.com/iframe_api"></script>
<script type="text/javascript">
function onYouTubeIframeAPIReady()
{
ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})
}
function onPlayerReady(a)
{
a.target.playVideo();
}</script>
<iframe id="playerId" type="text/html" width="250" height="180" src="http://www.youtube.com/embed/9qkXs768JKY?enablejsapi=1&rel=0&playsinline=1&autoplay=1" frameborder="0"></iframe>
And my ViewController has :
self.webView.allowsInlineMediaPlayback = YES;
self.webView.mediaPlaybackRequiresUserAction = NO;
Any help and guidance is appreciated. Thanks in advance.
Other attempt:
I have tried the code below inside the HTML file but now it shows a play button with a line through it. Any idea how to fix it?
<video width="280" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
<object data="movie.mp4" width="220" height="240">
<script type="text/javascript" src="http://www.youtube.com/iframe_api"></script>
<script type="text/javascript">
function onYouTubeIframeAPIReady()
{
ytplayer=new YT.Player("playerId",{events:{onReady:onPlayerReady}})
}
function onPlayerReady(a)
{
a.target.playVideo();
}
</script>
<iframe id="playerId" type="text/html" width="250" height="180" src="http://www.youtube.com/embed/9qkXs768JKY?enablejsapi=1&rel=0&playsinline=0&autoplay=0" frameborder="0"></iframe>
<!-- <embed src="http://www.youtube.com/embed/9qkXs768JKY" width="220" height="200">
</embed> -->
</object>
</source>
</source>
</video>
I am using this to play youtube videos in web views:
<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/XDJxoVIqdW0" frameborder="0">
For your UIWebView, you need to set allowsInlineMediaPlayback to YES in order to show the media in your app. It defaults to NO on the iPhone.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIWebView/allowsInlineMediaPlayback
Related
I'm creating a server for streaming videos. I use nginx and rtmp module.
But when I play video in my web, it works fine with Chrome and edge but Firefox is'nt.
Firefox shows this and I don't know why:
Here is my html file:
<video width="640" height="360" id="player1">
<source type="video/rtmp" src="rtmp://myserver:myport/livestreaming/live" />
<source type="application/x-mpegURL" src="http://myserver/livestreaming/live/index.m3u8" />
</video>
<script type="text/javascript" src="lib/demo/hls_streams.js"></script>
<script type="text/javascript">
function loadStream(url) {
$('video')[0].player.setSrc(url);
$('video')[0].player.play();
}
</script>
<script>
$('video').mediaelementplayer({
success: function(media, node, player) {
$('#' + node.id + '-mode').html('mode: ' + media.pluginType);
}
});
</script>
Can someone help me with this problem?
I'm having an issue with Iframe autoplay="0" on Google Chrome.
I have tried every thread and and forum and nothing has worked.
I need the video to pause as soon as the page loads. I cannot use the <video> </video> tag because I need information to pull from a separate library into a main video div.
I haven't found any JavaScript that works and autostart="0" , autostart="false" autoplay="0" , autoplay="false" doesnt work either.
Link : Aza TV
<script>
$(".video-1, .video-2, .video-3").on("click", function(event) {
event.preventDefault();
$(".video_case iframe").prop("src", $(event.currentTarget).attr("href"));
});
</script>
.video_wrapper { width:67%; padding:10px; box-sizing:border-box; float:left; min-height:50px;border: thin solid #F60; border-radius:5px 5px;}
.nextvideo_wrapper { width:31%; padding:8px; box-sizing:border-box; float:left; min-height:400px;border: thin solid #F60; border-radius:5px 5px;margin-left:10px; background:#333;}
<div class="video_wrapper">
<iframe name="someFrame" id="someFrame" width="100%" height="420" src="http://41.76.210.2/vod/azamusica_VictoriaKimani_webisode22_20151022_HDO.mp4?autoplay=0" controls ></iframe>
</div>
<div class="nextvideo_wrapper">
<iframe src="libraries/azamuzika.php" width="100%" height="400px" bg=ffffff&text=000000" frameborder="0"></iframe>
</div>
Please note your selector does not actually match the html you posted.
To keep it simple try to add &autoplay=0 to your urls - if that does not work, try this - I gave the actual iframe an ID of iFrame1 and write the video tag into it
var vid = '<video controls="controls"><source src="__VIDEO__" type="video/mp4" /><!--[if gt IE 6]><object width="640" height="375" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"><! [endif]--><!--[if !IE]><!--><object width="640" height="375" type="video/quicktime" data="__VIDEO__.mp4"><!--<![endif]--><param name="src" value="__VIDEO__" /><param name="autoplay" value="false" /></object></video>';
$(".video-1, .video-2, .video-3").on("click", function(event) {
event.preventDefault();
var ifrm = $('#iFrame1').get(0); // get the DOM object
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.write(vid.replace(/__VIDEO__/g,$(event.currentTarget).attr("href"));
ifrm.document.close();
});
I've tried all the possible solutions but nothing worked for local video bindings. I believe best solution would be to fix using jQuery.
$(document).ready(function () {
var ownVideos = $("iframe");
$.each(ownVideos, function (i, video) {
var frameContent = $(video).contents().find('body').html();
if (frameContent) {
$(video).contents().find('body').html(frameContent.replace("autoplay", ""));
}
});
});
Note: It'll find all the iframes on document ready and loop through each iframe contents and replace/remove autoplay attribute. This solution can be use anywhere in your project. If you would like to do for specific element then use the code under $.each function and replace $(video) with your iframe element id like $("#myIFrameId").
I have tried video tag, jw player. But nothing helped.
jw code,
<script type='text/javascript' src='jwplayer.js'></script>
<div id='mediaplayer'></div>
<script type="text/javascript"> jwplayer('mediaplayer').setup({ 'width': '480', 'height': '270', 'file': 'http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8', 'image': '/thumbs/sample.jpg', 'modes': [ {type: 'html5'}, {type: 'flash', src: '/player.swf'}, {type: 'download'} ] }); </script>
video tag,
<video width="300" height="200" controls> <source src="http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"> </video>
Can anybody suggest ideas to play .m3u8 in HTML page..
You need to supply the MIME type attribute in the video tag: type="application/x-mpegURL
<video width="300" height="200" controls> <source src="http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"
type="application/x-mpegURL> </video>
Is there a way to set thumbnail image on HTML5 video?
I want to see some pictures before play.
My code looks like this:
<video width="470" height="255" controls>
<source src="video.mp4" type="video/mp4">
<source src="video.ogg" type="video/ogg">
<source src="video.webm" type="video/webm">
<object data="video.mp4" width="470" height="255">
<embed src="video.swf" width="470" height="255">
</object>
</video>
Thanks!
Add poster="placeholder.png" to the video tag.
<video width="470" height="255" poster="placeholder.png" controls>
<source src="video.mp4" type="video/mp4">
<source src="video.ogg" type="video/ogg">
<source src="video.webm" type="video/webm">
<object data="video.mp4" width="470" height="255">
<embed src="video.swf" width="470" height="255">
</object>
</video>
Does that work?
Display Your Video First Frame as Thumbnail:
Add preload="metadata" to your video tag and the second of the first frame #t=0.5 to your video source:
<video width="400" controls="controls" preload="metadata">
<source src="https://www.w3schools.com/html/mov_bbb.mp4#t=0.5" type="video/mp4">
</video>
If you want a video first frame as a thumbnail, than you can use
Add #t=0.1 to your video source, like below
<video width="320" height="240" controls>
<source src="video.mp4#t=0.1" type="video/mp4">
</video>
NOTE: make sure about your video type(ex: mp4, ogg, webm etc)
I found the solution that I got from your example and other examples and made this:
<video id="video1" width="470" height="264" poster="video_poster.jpg" onclick="playPause()">
<source src="video.mp4" width="470" height="264" type="video/mp4" >
<source src="video.webm" type="video/webm" >
<source src="video.ogv" type="video/ogg" >
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="470" height="264" >
<param name="movie" value="video.swf" >
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="11.0.0.0">
<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
<param name="expressinstall" value="../../Scripts/expressInstall.swf">
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="video.swf" width="500" height="500">
<!--<![endif]-->
<param name="quality" value="high">
<param name="wmode" value="opaque">
<param name="swfversion" value="11.0.0.0">
<param name="expressinstall" value="../../Scripts/expressInstall.swf">
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
<p><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
Unfortunately Your browser is old and does not support full video experience.
</object>
</video>
<script>
var myVideo=document.getElementById("video1");
var att=document.createAttribute("poster");
if (myVideo.error) {
switch (myVideo.error.code) {
case MEDIA_ERR_NETWORK:alert("Network error - please try again later.");break;
case MEDIA_ERR_DECODE:alert("Video is broken.."); break;
case MEDIA_ERR_SRC_NOT_SUPPORTED:alert("Sorry, your browser can't play this video."); break;
}
}
else
{
function playPause()
{
if (myVideo.paused)
{
myVideo.play();
att.value="";
myVideo.setAttributeNode(att);
}
else myVideo.pause();
}
}
</script>
Fantastic work. Thanks!
<?php
$thumbs_dir = 'E:/xampp/htdocs/uploads/thumbs/';
$videos = array();
if (isset($_POST["name"])) {
if (!preg_match('/data:([^;]*);base64,(.*)/', $_POST['data'], $matches)) {
die("error");
}
$data = $matches[2];
$data = str_replace(' ', '+', $data);
$data = base64_decode($data);
$file = 'text.jpg';
$dataname = file_put_contents($thumbs_dir . $file, $data);
}
?>
//jscode
<script type="text/javascript">
var videos = <?= json_encode($videos); ?>;
var video = document.getElementById('video');
video.addEventListener('canplay', function () {
this.currentTime = this.duration / 2;
}, false);
var seek = true;
video.addEventListener('seeked', function () {
if (seek) {
getThumb();
}
}, false);
function getThumb() {
seek = false;
var filename = video.src;
var w = video.videoWidth;//video.videoWidth * scaleFactor;
var h = video.videoHeight;//video.videoHeight * scaleFactor;
var canvas = document.createElement('canvas');
canvas.width = w;
canvas.height = h;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, w, h);
var data = canvas.toDataURL("image/jpg");
var xmlhttp = new XMLHttpRequest;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
}
}
xmlhttp.open("POST", location.href, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send('name=' + encodeURIComponent(filename) + '&data=' + data);
}
function failed(e) {
// video playback failed - show a message saying why
switch (e.target.error.code) {
case e.target.error.MEDIA_ERR_ABORTED:
console.log('You aborted the video playback.');
break;
case e.target.error.MEDIA_ERR_NETWORK:
console.log('A network error caused the video download to fail part-way.');
break;
case e.target.error.MEDIA_ERR_DECODE:
console.log('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
console.log('The video could not be loaded, either because the server or network failed or because the format is not supported.');
break;
default:
console.log('An unknown error occurred.');
break;
}
}
</script>
//Html
<div>
<video id="video" src="1499752288.mp4" autoplay="true" onerror="failed(event)" controls="controls" preload="none"></video>
</div>
That seems to be an extra image being shown there.
You can try using this
<img src="/images/image_of_video.png" alt="image" />
/* write your code for the video here */
Now using jQuery play the video and hide the image as
$('img').click(function () {
$(this).hide();
// use the parameters to play the video now..
})
1) add the below jquery:
$thumbnail.on('click', function(e){
e.preventDefault();
src = src+'&autoplay=1'; // src: the original URL for embedding
$videoContainer.empty().append( $iframe.clone().attr({'src': src}) ); // $iframe: the original iframe for embedding
}
);
note: in the first src (shown) add the original youtube link.
2) edit the iframe tag as:
<iframe width="1280" height="720" src="https://www.youtube.com/embed/nfQHF87vY0s?autoplay=1" frameborder="0" allowfullscreen></iframe>
note: copy paste the youtube video id after the embed/ in the iframe src.
You need to use poster attribute in your video tag :
src="example.com"
poster="/video-thumbnail.png"
I am trying to stream video file on web. my server is httpd 2.2 runnin gon centos 5 64 bit. So far it has worked well with ie9, chrome, opera but I have issues with firefox. I cannot rely on a user to have certain plugins installed. I want the video to be able to play in html5 if not supported then roll onto flash. The following is the current code that I have.
<!DOCTYPE html>
<html>
<head>
<SCRIPT type="text/javascript" src="jquery-1.7.2.min.js"></SCRIPT>
<SCRIPT type="text/javascript" src="modernizr.custom.13466.js"></SCRIPT>
<script type="text/javascript" src="excanvas.js"></script>
<script type="text/javascript">
function supports_canvas() {
return !!document.createElement('canvas').getContext;
}
function supports_video() {
console.log("supports video");
console.log(document.createElement('video').canPlayType);
return !!document.createElement('video').canPlayType;
}
function supports_h264_baseline_video() {
if (!supports_video()) { return false; }
var v = document.createElement("video");
return v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
}
function supports_ogg_theora_video() {
if (!supports_video()) { return false; }
var v = document.createElement("video");
return v.canPlayType('video/ogg; codecs="theora, vorbis"');
}
function supports_webm_video() {
if (!supports_video()) { return false; }
var v = document.createElement("video");
return v.canPlayType('video/webm; codecs="vp8, vorbis"');
}
</script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
/*console.log("document ready");
if ( !supports_video() ) {
console.log("false");
return false;
}
*/
if (Modernizr.canvas) {
// let's draw some shapes!
} else {
// no native canvas support available :(
}
});
</script>
<!-- first try HTML5 playback: if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise -->
<!-- warning: playback does not work on iOS3 if you include the poster attribute! fixed in iOS4.0 -->
<video width="640" height="360" controls>
<!-- MP4 must be first for iPad! -->
<source src="movie.mp4" type="video/mp4" />
<!-- Safari / iOS video
<source src="movie.ogv" type="video/ogg" />-->
<!-- Firefox / Opera / Chrome10 -->
<!-- fallback to Flash: -->
<object width="640" height="360" type="application/x-shockwave-flash"
data="movie.swf">
<!-- Firefox uses the `data` attribute above, IE/Safari uses the param below -->
<param name="movie" value="movie.swf" />
<param name="flashvars"
value="controlbar=over&image=movie.jpg&file=movie.mp4" />
<!-- fallback image. note the title field below, put the title of the video there -->
<img src="movie.jpg" width="640" height="360" alt="__TITLE__"
title="No video playback capabilities" />
</object>
</video>
<!-- you *must* offer a download link as they may be able to play the file locally. customise this bit all you want
<p>
<strong>Download Video:</strong> Closed Format: "MP4" Open Format: "Ogg"
</p>-->
</body>
</html>
I have placed the following in .htaccess file and httpd conf
AddType video/mp4 mp4
AddType video/ogg ogg
AddType video/webm webm
I have also loaded the following into httpd
AddHandler h264-streaming.extensions .mp4
LoadModule h264_streaming_module /usr/lib64/httpd/modules/mod_h264_streaming.so
Message in firefox i get is: firefox no video with supported format
Any suggestions?
Firefox doesn't support MP4. If a browser supports HTML5 video, it will look for a file it can play. If it can't find one, it does not then fall back to the Flash version automatically, so for Firefox (and Opera - which also doesn't support MP4), you'll need to also provide a WebM format (and Ogg if you want to support Firefox 3.6).