Issues with Soundcloud iframe and YouTube iframe together - youtube-api

The Soundcloud widget works fine playing multiple tracks in succession. If I then hide that frame, play a youtube video in a youtube iframe, and then switch back to a new track in the Soundcloud widget, it loads but will not play (ignoring the autoplay setting and any widget.play() calls). I had this working on Chromecast with the developer preview SDK and the 1.0 cast receiver but now with the 2.0.0 receiver it's broken. Any ideas how to proceed?

Currently there is no supported mechanism in the SDK to play YouTube videos outside of the YouTube app. Note that in general, applications may not allow other senders launch or control their receiver side, for example Hulu+ may not like it if you wan to write your own app to launch and control that application on your Chromecast; if they decide to allow such model, they need to publish the steps (for example, they can publish their App ID and additional custom data that would link deep into their application). YouTube is no different in that respect.

ok, got this working so hopefully this is useful to others. Assuming only one is active and visible at a time, the trick is to destroy the prior widgets rather than try to reuse them. For YouTube this does not mean reloading the iframe_api but simply calling YTPlayer.destroy() and new YT.Player() next time around. For SoundCloud keep a handle of the iframe and then call iframe.parentNode.removeChild(iframe) to destroy and then create again next time.

Related

youtube-api - Event on timeupdate

Is it possible to raise an event when IFrame embedded YouTube reach a specific frame?
I am looking for something similar to HTML5 player timeupdate event.
I am not looking for using a setInterval to check the current position (as suggested in Youtube API event on a specified time), I would like to know if there is a native API to support such feature.
This is not possible as there is no such event within the iFrame API. Although it is not directly possible you could try something like this, if you need a video to end a specific point for example you can use load parameters to do this, like so.
loadVideoById({'videoId': 'bHQqvYy5KYo',
'startSeconds': 5,
'endSeconds': 60,
'suggestedQuality': 'large'});
After that you would hook into the onStateChange event and depends on what you want to do continue playing, ask a question about up to the timeframe etc.
However if this is designed to be used on mobile you must consider as per most mobile browsers (references says iOS, i think android does too).
"Warning: To prevent unsolicited downloads over cellular networks at the user’s expense, embedded media cannot be played automatically in Safari on iOS — the user always initiates playback."
So if a video ends or pauses you can not pragmatically restart/resume the video, the user must always do it.

JavaFX project play youtube videos

I work on an automatically music player. To be short, i use the Last.fm api to get a lot of tracks names and tags. Using these tags and some intelligence computing algorithms, once you play a track, the player sets another track (with tags very appropriate to the tags of the track listened before).
I used the youtube API to search for the URL's of the movies, and I managed to make it work. Now I want to make the videos play on my music player. I have tried to place the youtube player on WebView. It works, but not as intended. I want to control that player. I want it to start playing automatically, and I want to get noticed when the video ended so I can start the next one.
Any clues of what should I do to play the videos from youtube based on the search that uses the Youtube API, and to have control over the youtube player that I place on my GUI(make it play and stop from command line)? Or is there any possible way do download the youtube movie and play it using the JavaFX API? I searched google and noticed I cannot download youtube movie into a format that can be played by JavaFX api.
Update Dec 4th, 2015
Some versions of JavaFX 8 are unable to play back youtube video content. Currently, for instance, Java 8u66 cannot playback youtube video content, but Java 8u72 early access release can.
Also note some of the videos referenced in the sample solution are no longer available or are protected from play in embedded video players. So ensure that you perform any tests using available and videos that have not been distribution restricted. Refer to the youtube documentation for information on distribution restriction if need be.
Any clues of what should I do to play the videos from youtube
As a hints to get you started, see code playing YouTube videos in JavaFX and the YouTube HTML5 api.
Here is the sample code I linked running and playing YouTube videos back within a JavaFX WebView with some (very minimal) control over the video playback via interaction with a JavaFX "New Song" button.
Or is there any possible way do download the youtube movie and play it using the JavaFX API? I searched google and noticed I cannot download youtube movie into a format that can be played by JavaFX api.
I think such a usage would violate YouTube's terms of service. I believe YouTube requires you to play the video back using the YouTube video player (let's them insert ads in the video player etc).
5.1 A
you agree not to distribute any part of or parts of the Website or the
Service, including but not limited to any Content, in any medium
without YouTube's prior written authorisation, unless YouTube makes
available the means for such distribution through functionality
offered by the Service (such as the YouTube Player);
5.1 C
you agree not to access Content through any technology
or means other than the video playback pages of the Website itself,
the YouTube Player, or such other means as YouTube may explicitly
designate for this purpose;
I advanced little, but I got stuck to other problems.
First of all, the code from jewelsea was great. Now I could embed the player into a secondary window of my player and it shows the movie based on the URL that i got using the youtube api. But it looks like JavaFX cannot show most of the movies. It shows me the youtube player and an error message saying that I need to install latest version of Adobe Flashplayer. From my research, I noticed that the webView can only show movies with quality set at 240p, not higher.
I have searched a lot on Google how to make my webView to play the 240p quality video. First of all, i tried to set the youtube query parameters (https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters#formatsp). I tried all the parameters from there: 1,5 and 6. But yet, I did not get the URL of movie with format that can be viewed on the webView of the JavaFX.
I also tried to embed the video quality in the URL of the movie like this:
http:/www.youtube.com/watch?v=og2YZlLhjKs&vq=small:240p ; but it does not work at all. I also wrote that URL in the browser and it looks like the youtube automatically sets the video to the highest quality, no matter what parameter I write in the URL.
The youtube api code that I used is the same like in this webpage: http://www.javacodegeeks.com/2010/05/getting-started-with-youtube-java-api.html
I just moved the main class code to a method that returns the URL of the first video that is in the list, and I changed the " query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT); "
to " query.setOrderBy(YouTubeQuery.OrderBy.RELEVANCE);". And this works fine, it shows the url to proper music videos that I search.
I am sorry for not showing the code of my project but it is big and it contains 2-3 api keys, and if you tell me how to change the video URL http:/www.youtube.com/watch?v=og2YZlLhjKs to work on the code from this website: https:/gist.github.com/jewelsea/1437374 , then I will know that to do to make it work on my project as well;
And the thing about YouTube playback API also enlightened me. I see that API has a lot of functions that could help me to play a lot easier with the video content (make it play, make it stop) but the problem is that I do not have knowledge about javascript programming and it is very sad that I do not have those methods in Java API as well. Maybe I will give it a try and insert javascript code into my webview. But, if I edit the webview using javascript... Is it going to play higher quality movies on the JavaFX webView?

How does YouTube web start a video playback automatically on mobile Safari without a user's action?

YouTube web version can always play a video automatically on mobile Safari without a user's explicit action to the HTML video element. How does YouTube do this?
YouTube's actually done something quite tricky, if you click a video related to the current one or in the search, it doesn't actually load another page, it uses JavaScript to update the page to look like a different one, and then uses that same click handler to start the video, so the system thinks that it was user initiated. That's why if you enter the URL for a video straight into the address bar when not in YouTube it doesn't auto-start...

What is meant by 'separate, isolate, or modify the audio or visual components' in YouTube's API Terms of Service?

I'm trying to learn more about YouTube's TOS. More specifically:
II. Prohibitions
8: separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API;
I'm working inside of a Google Chrome Extension which consists of a persistant background page and a foreground pop-up page. I would like to display audiovisual content in the foreground to users. This is fine and works, however, upon closing the foreground -- the audiovisual content ceases because the page has been destroyed.
As such, I would like to sync two YouTube players such that one in the background is unmuted with the one in the foreground being muted, but with its visual content sync'ed to that of the background. Would this violate YouTube's TOS? I'm hoping the answer is no - it seems akin to having a tab open. Sometimes the visual content can be seen (at the user's discretion) but the audio content would be uninterrupted.
Thanks
If I interpret that correctly:
"to separate or isolate" means to cut off the video or the audio part (or even different channels of it, if any) of the returned/streamed media
"to modify" means that you transform the data in some way and you display it to the user, instead of the original data (i. e. you are prohibited to make a video streaming application that displays every movie in black and white).
So, unfortunately, I think your requirement does indeeed violate the TOS.
In short:
There's no way for you to make an app that allows you to listen to a youtube song with your display off...
(I believe they want you to see the ads or they want to prove to those who pay them to put the ads that people sees the ads they put on all youtube videos).

I want to automatically load local video and audio in a phone gap application on the iPad

I want to automatically load local video and audio without clicking/swiping, etc. on a PhoneGap application on the iPad. I'm considering creating an objective-c plugin, would this be the correct way or is there another work around i.e. a plugin, javascript way etc?
Given that a phonegap app is basically a wrapped webapp, I think you may be out of luck, apple requires a user action to play media on the iPad (actually, audio, I don't know either way for video). Here's a source.
See the user controls or media playback controls section. Even though your data is local, the play action is disabled without an action

Resources