Notifications on a youtube playing - ios

i've been struggling with this subject for ages, since there does not seem to be a concrete answer.
I'm creating a playlist of youtube videos and i would like to get notification when you press fastforward and so.The problem is my youtube video is being played by a htmlsting, which does not use a MPMoviePlayerController property. Therefor i cant use NSNotifications, which i need.
a lot of people telling me to use LBMoviePlayer or other sample codes there are extracting the youtube video. The problem is that, this is illegal and probably wont make the app through the review.
My question is then. Can it really be true that there are no way to play a youtube video and get notifications when any of the buttons pressed, without using an extractor?
my code atm:
NSString *youTubeVideoHTML = #"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> 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; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%#', events: { } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
embedHtml = [NSString stringWithFormat: youTubeVideoHTML,
webView.frame.size.width,
webView.frame.size.height,
[[array valueForKey:#"link"] objectAtIndex:0 ]];
[webView loadHTMLString: embedHtml baseURL: [NSURL URLWithString: #"http://youtube.com"]];

Related

Apple TV overlay audio of video

I want to build an Apple TV app that plays a list of short videos and plays music over them.
To achieve this I need to do two following things:
1) Mute the videos or remove the audio tracks from them
I have no Idea if/how this is possible. I looked around the TVJS documentation for Player and MediaItem but found nothing.
2) Play two media items at the same time.
From this I already know that this is at least not possible with two players. I also tried to use the background audio of my TVML Template but this didn't work either.
Does anyone know of a way how something like this would be possible?
Edit (some more information):
For testing stuff I used the code from this article
At the suggesion of Daniel Storm I tried to change the load function in Presenter.js to both
load: function(event) {
var self = this,
ele = event.target,
videoURL = ele.getAttribute("videoURL")
if(videoURL) {
var player = new Player();
var playlist = new Playlist();
var mediaItem = new MediaItem("video", videoURL);
player.playlist = playlist;
player.playlist.push(mediaItem);
mediaItem.volume = 0.0;
player.present();
}
},
and
load: function(event) {
var self = this,
ele = event.target,
videoURL = ele.getAttribute("videoURL")
if(videoURL) {
var player = new Player();
var playlist = new Playlist();
var mediaItem = new MediaItem("video", videoURL);
player.playlist = playlist;
player.playlist.push(mediaItem);
player.volume = 0.0;
player.present();
}
},
but neither worked.

Play control buttons aren't shown when playing youtube video from uiwebview

I'm trying to play a YouTube video inside a UIWebView in Swift, when the video goes on full screen I get a message on the header and the playback buttons aren't shown, I tried everything and tried to use google's YTPlayerView but it is the same issue, please help me solving this issue.
here is the code:
let htmlString = "<html><body style='margin:0px;padding:0px;'><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){}</script><iframe
id='playerId' type='text/html' width='\(UIScreen.mainScreen().bounds.width)' height='\(self.imageCollectionView.frame.height)' src='\(url!.description)?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'></body></html>"
cell.vedioWebPage.allowsInlineMediaPlayback = true
cell.vedioWebPage.mediaPlaybackRequiresUserAction = false
cell.vedioWebPage.loadHTMLString(htmlString, baseURL: NSBundle.mainBundle().resourceURL)
and here is a screenshot:

Link to specific time in a youtube video via seekTo();

I’m trying to get something like an index page of a youtube video so that there are links to specific times of the video.
I tried it to do like explained in Links to Specific Times in YouTube iframe embed, but somehow it doesnt seem to work.
This is my code:
<script>
var tag = document.createElement('script');
tag.src = "//www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('video', { events: {'onReady': onPlayerReady}});
}
function playerSeekTo(seconds) {
player.seekTo(seconds);
}
</script>
HTML:
<iframe src="https://www.youtube.com/embed/FKWwdQu6_ok?enablejsapi=1" frameborder="0" allowfullscreen id="video">
</iframe>
Link to 1 minutes 10 seconds
Link to 1 minutes 30seconds
Link to 1 minutes 50 seconds
I encountered three problems:
1st
tag.src = "//www.youtube.com/player_api";
led to an error. Should be
tag.src = "http://www.youtube.com/player_api";
2nd
player = new YT.Player('video', { events: {'onReady': onPlayerReady}});
Obviously, onPlayerReady is not defined. When you remove this part, it'll work fine. What do you want to achieve with this?
player = new YT.Player('video');
(3rd)
To me, the video you embed is not available. When I embed another video (e.g. Im69kzhpR3I), everything behaves as it should.

Get YouTube url from UIWebView

How do I get the url from a youtube video that is being played in a UIWebView?
Once the YouTube video was loaded into the webView, I created a button that the user can tap to copy the URL to a text field on the same page. The trick is to get the innerHTML of the page and then look for the YouTube ID. With this ID I then put it into a full url so that the user can save the link and play back the video at a later date without having to look for that video again on the YouTube site. (BTW, I have my own displayAlert that takes the given message and displays it to the user when there isn't a video loaded in the UIWebView or there are many videos loaded) Here is the code:
-(IBAction)copyURLAction {
if (webView) {
NSString* htmlString = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.innerHTML"];
if (htmlString) {
NSString *youTubeID = #"data-youtube-id=\"";
int position = [htmlString rangeOfString:youTubeID].location + [youTubeID length];
if (position > 1) {
htmlString = [htmlString substringFromIndex:position];
position = [htmlString rangeOfString:#"\""].location;
htmlString = [htmlString substringToIndex:position];
NSString* tempPrefix = #"http://m.youtube.com/watch?v=";
NSString *youTubeString = [tempPrefix stringByAppendingString:htmlString];
textFieldView.text = youTubeString;
} else {
[[SharedObjectsSingleton sharedInstance] displayAlert:#"Can't Copy URL" :#"Can only copy the URL when a single video is being displayed."];
}
} else {
[[SharedObjectsSingleton sharedInstance] displayAlert:#"Can't get URL" :#"Nothing to copy."];
}
}
}
The code above used to work but i think youtube have changed the script so now in order for it to work you need to replace
#"data-youtube-id=\"" with #"i.ytimg.com/vi/"

Google Picker API: filter YouTube movies

Hello I've been expirimenting with the Google Picker API (http://code.google.com/apis/picker/). I've got a working demo (code below) that searches for YouTube movies.
This current version returns all videos. I'm trying to filter the results so it'll only list search results from youtube.com. The picker API supports this. But I don't understand the API documentation.
The documentation (http://code.google.com/apis/picker/docs/reference.html) mentions 'VideoSearchView.YOUTUBE' and describes it as "A string constant suitable for the VideoSearchView.setSite() method".
I don't understand how to implement this filter in my code below. Any help is appreciated.
<!--
Needs work; it should only display YouTube videos.
http://code.google.com/apis/picker/docs/reference.html
Change the key parameter for a domain+path specific API key. Get one here: http://code.google.com/apis/loader/signup.html.
-->
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAANAaPTI0Sup-knGFaDbCNHBSXhCTdTCKo5q_OHnpA1qEpBIP8mRTtPnObFFbe_J21oviL78C86yxHUA"></script>
<script type="text/javascript">
google.load('picker', '1', {'language':'nl'});
function googlePicker()
{
/*
Displays the users own YouTube movies:
picker = picker.addView(google.picker.ViewId.YOUTUBE);
Displays all videos:
picker = picker.addView(google.picker.ViewId.VIDEO_SEARCH);
Displays all videos from youtube.com:
???
Example query that returns non-YouTube results: "Mobile Healing Rooms: Following Jesus on Vimeo"
*/
var picker = new google.picker.PickerBuilder();
picker = picker.addView(google.picker.ViewId.VIDEO_SEARCH);
picker = picker.enableFeature(google.picker.Feature.NAV_HIDDEN);
picker = picker.setTitle('Selecteer een YouTube video');
picker = picker.setCallback(googlePickerCallback);
picker = picker.build();
picker.setVisible(true);
}
function googlePickerCallback(data) {
var youTubeUrl = (data.action == google.picker.Action.PICKED) ? data.docs[0].url : '';
if (youTubeUrl != '')
{
$('#block_youtube_url').val(youTubeUrl);
}
}
</script>
Try the equivalent of the following:
// Create and render a Picker object for searching YouTube videos.
function createPicker() {
var picker = new google.picker.PickerBuilder().
addView(new google.picker.VideoSearchView().
setSite(google.picker.VideoSearchView.YOUTUBE)).
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
If you add views by ViewId, you don't get a chance to call view-specific methods. This is why some View-derived classes are exposed.

Resources