Youtube iframe API: Differentiate "playing because click" versus "playing because playVideo()" - youtube

A youtube player has this handler for the onStateChange event:
function onPlayerReady(event) {
if (event.data == YT.PlayerState.PLAYING) {
if (event.something) {
console.log("The player is playing because the user clicked the 'play' button")
} else {
console.log("The player is playing because player.playVideo() was called programatically");
}
}
}
Question:
Is there a property, something, in the object event that I could use for determining the source of the playing state ?
I need to differentiate the playing state in its two possible causes:
Playing because the user clicked the "play" button
Playing because the code programatically called player.playVideo()
Is this possible with the API? if not, any ideas on how to achieve it in an elegant manner?

The YouTube Iframe Player API does not expose any events from the player controls themselves, and I don't think that wrapping things in a DIV will help, as click events don't bubble up past an iFrame. You could embed a chromeless player and then construct your own player controls bar; that way, you'd have full access to your control buttons and could capture click events on them.

Related

How to pause JW Player on Ipad without controls

JW player, if you hide the control bar you can click the video to play and pause, this works fine in desktop.
When I tested this in ipad it plays but touching it again doesn't pause the video.
Verify with this URL, https://support.jwplayer.com/customer/portal/articles/1406723-basic-video-embed
**Dont use the control bar as I need it disabled.
If you hide the JW controls, then the player should also not react to clicking on the video as a means to start/stop unless you specifically add code to tell it to.
For this to happen you need to attach a function to the onDisplayClick event listener as follows:
**JW6 version**
jwplayer().onDisplayClick(function(){
jwplayer().play();
});
**JW7 version**
jwplayer().on('displayClick',function(){
jwplayer().play();
});
Just calling the play() method in this way will handle the toggle of play/pause states - you don't need to manage this yourself.
I tried to do it in proper way but that doesn't seem to work alright, this is the only solution works for me,
$('.video-wrapper').on({ 'touchend' :
function(){
if(dtjwplayer.getState() !== 'paused') {
dtjwplayer.pause(true);
}
}
});
This is a very basic requirement where people wants to disable the control bar, Please let me know if there is any better way to do it.

WKWebView not playing next video in background

I have a WKWebView() that plays embedded YouTube videos. I'm passing in an array of video IDs to the YouTube JS API and displaying videos in the web view. In the foreground, videos play automatically, one after the other.
When my app enters the background, the video resumes playing (thanks to evaluateJavaScriptWithString()). However, based on whether I enter the background by clicking the home button or the sleep/wake (lock) button, the WKWebView() will do one of two things when the next video loads:
If I press the sleep/wake (lock) button, the videos will continue playing consecutively even in the background, as it should. Granted, I always get this notification:
2015-12-16 01:34:26.793 App[10335:1967149] ** -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] ** unhandled action -> <FBSSceneSnapshotAction: 0x13c36f240> {
handler = remote;
info = <BSSettings: 0x13c36b0f0> {
(1) = 5;
};
}
...but the videos keep on playing. Now, when I press the home button, the following video will not play. It will stop at the end of the currently played video and not play the next video, even if I call a custom play() function on the web view.
I have Javascript code for the YouTube iFrame that lets me control the player. When the player state changes (when a video ends), the following code is called. I'm wondering if window.webkit.messageHandlers.callbackHandler.postMessage() has anything to do with it.
var index = 0
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.UNSTARTED) {
var message = "next video index:"+index
try {
console.log('Video has ended');
window.webkit.messageHandlers.callbackHandler.postMessage(message);
} catch(err) {
console.log('The native context does not exist yet');
}
}
}
My question is: iOS is clearly able to load the next videos in the background as shown by the sleep/wake (lock) button. It does so without fail. Why isn't this the case after entering the background via the home button? It's the same background mode.

how to play video with native player instead of web player for a <video> tag?

We have a UIWebView that load html page including video tag. When the user tap the video element, a fullscreen movie player is presented.
As there is some logic in the web page that handle events and need to stop and close the movie player. Is there any API to do so (stop the web movie player and exit fullscreen)?
Any one know how to do this?
Further more, even we want to detect tapping on the video element, then we'll have to provide our own custom player, instead of the system web player. Any way to do it?
Thank you!
This might be helping, if you want to controll the HTML5 video with js: http://www.w3.org/2010/05/video/mediaevents.html
I am not shure if - on a mobile device - javascript will be running while the video is in fullscreen mode.

How do I add a "Mute Sound" button in SpriteKit / Objective C?

I'm programming a little SpriteKit game and I want to add a mute button, so that you can hear your own music while playing my game. Currently I'm just stopping the audio playback for the scene the mute button is in (main menu). However my game still automatically stops the user music even if the audio playback is stopped. How can I prevent that?
Also, I'd like to pass the information that the mute button is pressed (located in the main menu) to my game scene, so that I can also mute the music there, how do I do that?
Basically how do I pass a variable value from one scene to another?
What I did a while ago is check if the iPod Player is working and give it priority over the game music. (ie. Check if iPod is playing to actually start game music, as ipod music player will usually overwrite you game's music if you are using AVAudioPlayer.
+ (bool) IsIpodPlaying{
if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying
|| [[MPMusicPlayerController applicationMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying){
NSLog(#"iPod IS playing");
return true;
}else{
NSLog(#"iPod NOT playing");
return false;
}
}
Obviously you can do the same for your mute button. Ignore any action if iPod is playing, otherwise stop your game music.
To pass the information when the Mute button is pressed you can (in order of personal preference):
Set your Menu scene as a delegate of your Game scene and create a method to enable or disable sounds (ie. userDidEnableSound: )
Create a SoundControl singleton class that has the enable and disable sound methods and access them wherever you want.
Send a notification using the NSNotificationCenter and wait for it in the menu.

Fire object's method in titanium List view

Hi guys i am currently developing for IOS 7 with Titanium SDK 3.2.1.GA and i am in need of help.
I can't find anything on how to call an object's method within a list view
Basically i have a list view with a video player in each cell and a play button on top of it, i want the video player to start playing once the user clicks the play button, but i don't know how to fire the video player's play() method from within the list view.
Thank you for your help in advance
If you posted your code it would be easier to help you, but heres the general idea. Just listen on the itemClick event, then fire the play button for that ListItem:
// Keep an array of video players or something like that
var vidPlayersRefs = [...,...,...];
listView.addEventListener('itemclick', function(e){
// Get the video player for that row
var videoPlayer = vidPlayersRefs[e.itemIndex];
videoPlayer.open();
});

Resources