Youtube embed trouble with chrome - html

I am using this code
<div onclick="thevid=document.getElementById('thevideo');
thevid.style.display='block';
this.style.display='none'">
<img src="../img/film.jpg" style="cursor:pointer" />
</div>
<div id="thevideo" style="display:none">
<iframe width="600"
height="335"
src="https://www.youtube.com/embed/MZ-NmMMTyTU?&rel=0&theme=light&showinfo=0&disablekb=1&hd=1&autohide=1&color=white&autoplay=1"
frameborder="0"
allowfullscreen>
</iframe></div>
</div>
To embed a YouTube video on my site, and it is working fine in Firefox. But in Chrome the video starts playing, behind the image i have placed on top.
Any ideas how to fix this?

I just made one YouTube handler, with Javascript API.
HTML code:
<b id="youbox" class="youbox youbox-left">
<div id="player"></div> <!--player will loads here-->
</b>
<div id="youtube-select" class="youtube-select clearfix">
<ul>
<!-- use this part as a dynamic block, so you can multiply this -->
<li class="playanothervideo {ACTIVE}" rel="{YOUTUBE VIDEO ID}">
<h1>{TITLE OF VIDEO}</h1>
</li>
<!-- end of dynamic block. important: at the dom ready you have to make one li active, because that will be the first loaded video -->
</ul>
</div>
The javascript
if (($("#youbox").size() > 0)) // if you have youbox, which means you want a youtube player
{
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player; // insert youtube player api to the html source, and make a player instance
function onYouTubePlayerAPIReady() // on youtube player api loaded
{
player = new YT.Player('player', {
height: '350', // height of player
playerVars: { 'color': 'white', 'theme': 'light', 'modestbranding': 1, 'rel':0, 'showsearch':0, 'showinfo': 0, 'iv_load_policy': 3, 'hd': 1, 'controls':1}, // personalize players lookout (this is white instead of red)
width: '629', // width of player
videoId: $("#youtube-select li.active").attr("rel"), // aye, this is the first video id's getter
events:
{
'onReady': onPlayerReady, // the easiest event handling, calls onplayerready fn
}
});
}
function playAnotherVideo(id) // play another video event handler
{
if (player.getPlayerState() == 1) // if video is playing
{
console.log("playerstate ok")
player.stopVideo(); // stops video
player.loadVideoById(id); // load other
player.playVideo(); // starts other
}
else
{
player.cueVideoById(id); // if not playing just loads the other video's thumbnail
}
}
function onPlayerReady(event)
{
event.target.setPlaybackQuality("hd720"); // setting 720p resolution by default (it's not tested yet, sorry)
}
}
and from an other js, but can apply to the first:
$(".playanothervideo").live("click", function(){
playAnotherVideo($(this).attr("rel"));
pickMe($(this), "active");
});
function pickMe(e, c) {
e.siblings(e[0].tagName).removeClass(c);
e.addClass(c);
}
which select the videos and handle their active class.
Good luck with Youtubein. :)
For more informations check: https://developers.google.com/youtube/js_api_reference

Related

How to bind the paused attribute of video element in vue.js to a function which can display/hide play button

We need to display the play button on video window if video is paused even if video buffer has enough data (this will happen in safari browser as Safari doesn't allow to play the videos without user intervention). I added event listener for pause event. The code is as given below (please note that this is .vue file)
<template>
<div id="app" #keydown="handleKey($event)">
<video ref="videoRef" src="" id="videoID" width="100%" v-on:pause="onVideoPause"></video>
<div id="videoCC"></div>
<button type="button" id="playVideo" v-on:click="onClickCallback"><img :src="require('#/assets/playVideo.png')"></button>
<router-view tabindex="1"></router-view>
</div>
</template>
export default {
name: 'app',
methods: {
onClickCallback: function () {
console.log('onClickPlayback is called')
let videoPlayer = player.instance()
videoPlayer.play()
videoPlayer.setLogLevel(4) // Set Log level to debug
let playVideoBtn = document.getElementById('playVideo')
// Video is playing. Hide the play button
if (playVideoBtn.style.display === 'block') {
playVideoBtn.style.display = 'none'
}
},
onVideoPause: function () {
console.log('video is paused')
let videoEl = document.getElementById('videoID')
if ((videoEl.readyState > 2) && (videoEl.ended === false)) {
console.log('video buffer has the data and video is not ended')
document.getElementById('playVideo').style.display = 'block'
}
}
}
Basically when video is paused, onVideoPause() is getting called and if video is not ended, I am displaying the play button. In the click handler of the play button, I am playing the video and hiding the play button, But we faced below problem while testing with javascript console as below.
Video is playing. Used pause() from javascript console.
document.getElementById('video').pause()
Play button displayed but when we play() now from console, the button is not getting hidden as we are hiding the play button in click function of play button only. When I suggested we will add event listener for play also on video element, my reviewer suggested me to evaluate if we can do v-bind for the 'paused' attribute of video element.
If we can bind the paused attribute and if we can call a function when ever the value changes, we can do the hiding and display in that function. I am not able to figure out how can we bind the attribute and call the function whenever the value changes as v-bind only works with single expression. I am new to vue.js. Can any one please help me if this is possible with v-bind or with any other Vue directives?
my reviewer suggested me to evaluate if we can do v-bind for the
'paused' attribute of video element
The answer to that question is "no". The video element is not a Vue instance, so its properties are not reactive. You must rely on events to detect changes. I demonstrated a two-way binding in my other answer. Here is another approach that is a little simpler in terms of coding.
new Vue({
el: 'main',
data: {
videoElement: null,
paused: null
},
methods: {
updatePaused(event) {
this.videoElement = event.target;
this.paused = event.target.paused;
},
play() {
this.videoElement.play();
},
pause() {
this.videoElement.pause();
}
},
computed: {
playing() { return !this.paused; }
}
});
<script src="//unpkg.com/vue#latest/dist/vue.js"></script>
<main>
<video id="videoElement" controls poster="velocity-thumbnail.jpg"
#canplay="updatePaused" #playing="updatePaused" #pause="updatePaused">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-Mobile.mp4" type="video/mp4" media="all and (max-width:680px)">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-Mobile.webm" type="video/webm" media="all and (max-width:680px)">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-SD.mp4" type="video/mp4">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-SD.webm" type="video/webm">
<p>Sorry, there's a problem playing this video. Please try using a different browser.</p>
</video>
<div class="controls">
<button v-show="paused" #click="play">▶</button>
<button v-show="playing" #click="pause">⏸</button>
</div>
</main>
The general technique for two-way binding is:
in the bind phase, you install event listeners on the element to update the bound value
in the update phase, you move your bound value into the element.
In your case, you want to listen for the playing and pause events, and set a single playing variable appropriately. (paused is just !playing)
In the example below, I leave the controls on the video player and also add my own. You can use either control, and they stay in sync. (You should also remove the event listeners in the unbind phase. I didn't do that, because it's a little messy, and I wanted to keep the example short and simple.)
new Vue({
el: 'main',
data: {
playing: false
},
computed: {
paused() {
return !this.playing;
}
},
directives: {
play: {
bind(el, binding, vnode) {
el.addEventListener('playing', () => {
vnode.context[binding.expression] = !el.paused;
});
el.addEventListener('pause', () => {
vnode.context[binding.expression] = !el.paused;
});
vnode.context[binding.expression] = !el.paused;
},
update(el, binding) {
if (el.paused) {
if (binding.value) {
el.play();
}
} else if (!binding.value) {
el.pause();
}
}
}
},
methods: {
play() {
this.playing = true;
},
pause() {
this.playing = false;
}
}
});
<script src="//unpkg.com/vue#latest/dist/vue.js"></script>
<main>
<video id="videoElement" controls poster="velocity-thumbnail.jpg" v-play="playing">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-Mobile.mp4" type="video/mp4" media="all and (max-width:680px)">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-Mobile.webm" type="video/webm" media="all and (max-width:680px)">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-SD.mp4" type="video/mp4">
<source src="https://s3-ap-northeast-1.amazonaws.com/daniemon/demos/Velocity-SD.webm" type="video/webm">
<p>Sorry, there's a problem playing this video. Please try using a different browser.</p>
</video>
<div class="controls">
<button v-show="paused" #click="play">▶</button>
<button v-show="playing" #click="pause">⏸</button>
</div>
</main>

Show a loader while waiting for the iframe to load according to the link clicked, and hide the loader after iframe has loaded using AngularJS

I'm trying to show a loader while waiting for the iframe to load according to the link clicked. I use Semantic UI's loader. So far, what it can do is show the loader once the link is clicked. However, the loader will not disappear anymore, even after the iframe document has loaded.
Here is the HTML code:
<div class="drive-link">
<div ng-if = "!READY.value"> <!-- to check if the link has been clicked -->
<div class="ui active centered inline loader"></div>
</div>
<iframe name="embedded-iframe" allowfullscreen="" frameborder="0" iframe-onload></iframe>
</div>
<div class="active content">
<a target="embedded-iframe" href="{{file.link}}" ng-click="show_file_name(file)"> {{file.name}} </a>
<div ng-repeat="next_file in files | limitTo:files.length:$parent.$index">
<a target="embedded-iframe" ng-if="$index > 0 && next_file.category_id == file.category_id" href="{{next_file.link}}" ng-click="show_file_name(next_file)">{{next_file.name}}</a>
</div>
</div>
AngularJS code:
app.controller('mainController', function($scope) {
$scope.READY = {value:true};
$scope.show_file_name = function(file){
$scope.fileName = file.name;
$scope.fileDesc=file.description;
$scope.READY = {value:false};
}
});
app.directive("iframeOnload", function() {
return function(scope) {
scope.READY.value = true;
console.log(scope.READY.value)
};
});
I have a directive to iframe, called iframe-onload. I was thinking that if the anchor tag was clicked, it would somehow connected to the iframe (since clicking the anchor tag would show the embedded document anyway), and it would trigger iframe-onload, which would change READY's value. However, this was not the case, and iframe-onload would only be triggered once, when the HTML page loaded.
Note:
I'm trying to to stay away from timeouts because I don't think hard coding how long the loader will show is the best way to go.
Any help will be very much appreciated. Thank you!
Use simple approach which is that use ng show with your loader code. for example if you have loader in gif image like this
Link To be click
<img src="loader.gif" ng-show="loader"/>
and then in controller you can do like this
$scope.loader=false;
$scope.activateLoader=function(){
$scope.loader=true;
}
this is html table where my data loads.
<tr ng-if="!isDataLoading" ng-repeat="x in companies">
<td>{{x.Id}}</td>
<td>{{x.CompanyName}}</td>
<td>{{x.ContactPerson}}</td>
<td>{{x.TotalRerrals}}</td>
<td>{{TotalRegistered}}</td>
<td>{{x.TotalConverted}}</td>
<td>{{x.TotalSalesAgents}}</td>
<td class="text-green"><i class="fa fa-circle"></i> {{x.AccountStatus}}</td>
</tr>
<div ng-if="isDataLoading" style="width: 100px; margin: auto;">
<img src="assets/loader.gif" style="width: 100px; height: 100px;">
</div>
and here is my controller code
User.getCompanies().success(function(res) {
console.log('All companies', res);
if (res != null || res != "") {
$scope.customers = res;
$scope.companies = [];
for (var i = 0; i < res.length; i++) {
$scope.companies.push({
Id: res[i].Id,
AccountStatus: res[i].AccountStatus,
CompanyName: res[i].CompanyName,
ContactPerson: res[i].ContactPerson,
TotalConverted: res[i].TotalConverted,
TotalRegistered: res[i].TotalRegistered,
TotalRerrals: res[i].TotalRerrals,
TotalSalesAgents: res[i].TotalSalesAgents,
})
}
}
$scope.isDataLoading = false;
})
.error(function(err) {
console.log('error', err);
$scope.isDataLoading = false;
})
You can take this as an example. and change this code according to your need.

HTML5 <audio> Random Audio

i'm back from nowhere.
I have something for school where we need to make a website.
Everyone in my class uses those easy drag 'n drop builders.
I'm ofcourse making it with Notepad++.
So, a 1990 looking page is ofcourse not enough with some fun music.
I have found around 3 to 4 Mario Bros online music to use.
But it only starts the first source link, never the others.
I want to know how to do it, Google doesn't really help.
This is my code:
<audio autoplay="autoplay" controls="controls" title="Radio implented by Rootel">
So my question is, how do I autoplay this list? I didn't give a full list of the music, sorry.
Here you can make it with javascript!
//javascript
var _player = document.getElementById("player"),
_playlist = document.getElementById("playlist"),
_stop = document.getElementById("stop");
// functions
function playlistItemClick(clickedElement) {
var selected = _playlist.querySelector(".selected");
if (selected) {
selected.classList.remove("selected");
}
clickedElement.classList.add("selected");
_player.src = clickedElement.getAttribute("data-ogg");
_player.play();
}
function playNext() {
var selected = _playlist.querySelector("li.selected");
if (selected && selected.nextSibling) {
playlistItemClick(selected.nextSibling);
}
}
// event listeners
_stop.addEventListener("click", function () {
_player.pause();
});
_player.addEventListener("ended", playNext);
_playlist.addEventListener("click", function (e) {
if (e.target && e.target.nodeName === "LI") {
playlistItemClick(e.target);
}
});
.selected {
font-weight: bold;
font-size:20px;
}
<!--html-->
<audio id="player"></audio>
<ul id="playlist"><li data-ogg="http://www.lunerouge.org/sons/sf/LRWeird%201%20by%20Lionel%20Allorge.ogg">Space 1</li><li data-ogg="http://www.lunerouge.org/sons/sf/LRWeird%202%20by%20Lionel%20Allorge.ogg">Space 2</li><li data-ogg="http://www.lunerouge.org/sons/sf/LRWeird%203%20by%20Lionel%20Allorge.ogg">Space Lab</li></ul>
<button id="stop">Stop</button>
hope it helps!!!

Angularjs + HTML play youtube on mouse over

I want to play a movie once the mouse is hovering over it. Just like facebook.
<div class="col-sm-12">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="//www.youtube.com/embed/pQIXz-uhjIk">
</iframe>
</div>
</div>
The site is built with angularjs and html.
(Im quite new so please if possible also explain the solution not just paste code)
Br
Build up a solution "like" facebook in this plunker
To dynamically run the player, you'll have to integrate the ifram api.
You have to add this into your index.html
<script src="https://www.youtube.com/iframe_api"></script>
Then you need to handle the asynchronous load of their API (dunno why they did that) like this in your controller:
//i create a promise to wait for the YT.loaded to be true
var defered = $q.defer();
var promise = defered.promise;
//i launch this function until the YT.loaded is true
var interval = $interval(function(){
if(YT.loaded){
//if the YT api is loaded, i cancel the interval and resolve the promise
defered.resolve();
$interval.cancel(interval);
}
})
Now i can create a player when the YT api is ready :
var videoId = "pQIXz-uhjIk";
//when the API is ready
promise.then(function(){
//i create an Iframe player in the div with the "ytplayer" id
$scope.ytplayer = new YT.Player('ytplayer', {
height: '200',
width: '300',
videoId: videoId
}) ;
});
Now i have a full control on the player with the $scope.ytplayer object.
I prepare two function to start and pause a player :
$scope.startPlayer = function(player){
player.playVideo();
};
$scope.pausePlayer = function(player){
player.pauseVideo();
}
Now let see the HTML and the mouse tricks :
<div ng-show="ytplayer" ng-mouseenter="startPlayer(ytplayer)" ng-mouseleave="pausePlayer(ytplayer)" class="embed-responsive embed-responsive-16by9">
<div id="ytplayer"></div>
</div>
I show my div only if ytplayer is set. When i enter the div i run startPlayer() on the player ytplayer. When i leave the div i run pausePlayer() on the ytplayer.
The embed-responsive class is an inline-block to wrap the player
... And that's pretty much all.
Michelem's solutionis probably the best option and easiest option if you only have to start the player on mouseenter. But if you need more control on the player keep in mind my solution (even if it's a bit tricky).
Hope it helped.
This could be a solution you can play with:
JSFiddle
HTML:
<div ng-app="myApp" ng-controller="dummy">
<div class="col-sm-12">
<div class="embed-responsive embed-responsive-16by9">
<div ng-hide="url" ng-mouseenter="url = 'http:////www.youtube.com/embed/pQIXz-uhjIk?autoplay=1'">OVERME</div>
<iframe ng-show="url" class="embed-responsive-item" ng-src="{{trustSrc(url)}}"></iframe>
</div>
</div>
</div>
JS:
angular.module('myApp', [])
.controller('dummy', ['$scope', '$sce', function ($scope, $sce) {
$scope.trustSrc = function (src) {
return $sce.trustAsResourceUrl(src);
}
}]);

How do I play a sound with 360player (soundmanager2)?

I've set up soundmanager:
soundManager.setup({
And I've created a sound:
soundManager.createSound({
From the console I also have threeSixtyPlayer:
threeSixtyPlayer.init()
threeSixtyPlayer.init(): Found 0 relevant items.
So how do I make the 360player play the sound? And how do I detect that it is finished playing so that I can create and play the next one after that?
The docs lack information regarding 360ui but from what I've tried:
HTML code needed:
<div id="sm2-container"></div>
<div class="ui360 ui360-vis">
<a id="song_link" class="sm2_link" href="asfgasg.mp3"></a>
</div>
JS:
soundManager.setup({
url: 'inc/soundmanager/',
flashVersion: 9,
useFlashBlock: true,
onready: function() {
soundManager.createSound('someSongId_', selectedSong);
},
ontimeout: function() {
// Error msg
}
});
You also need the files (depending on the theme you want):
flashblock.css
360player.css
360player-visualization.css
berniecode-animator.js
360-button-vis-play-light.png
360-button-vis-pause-light.png
After that there should be a div with a "play" image.
To play you can use soundManager.getSoundById('myId') and chain it with the onfinish event. Example at the doc:
soundManager.play('myId',{
onfinish: function() {
alert('The sound '+this.id+' finished playing.');
}
});
Hope it helps...