How to access built-in media player opened by a UIWebView? - ios

Currently, when a user clicks play button on the video player which is located at a webpage which is opened inside my UIWebView, built-in media player pops-up and covers entire screen.
I'm looking for a way to access that particular movie player instance so I can interact with it.
Is it something doable? If so, how?

I would suggest to create UIButton to run javascript code. For example, below I created a function to control play/pause youtube video.
- (void)clickPlayButton {
NSString *jsCode = [NSString stringWithFormat:#"document.getElementsByClassName('ytp-play-button')[0].click()"];
[myWebView stringByEvaluatingJavaScriptFromString: jsCode];
}

Related

Can I use Youtube IFrame Player API as audio player?

I am using Youtube IFrame Player API on my own web project.
I am trying to use it as an audio player, so I hide iframe, and add a button which call playVideo() function.
I am wondering if it is legally okay to hide everything (iframe, logo, controller, everything) and use it as audio player.
Is there any legal problem for commercial use?

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 to custom video player of UIWebView

I want to make a customized video player for UIWebView.
I have 2 ideas about it:
1. hook the notifications of UIMoviePlayer***, but I can't get any information about the current player from the notification, so I can't replace it with my custom video player
2. replace video.play in js, use my js to tell objective c to launch my video player. But it only works for some website, not for all.
Is there any solution for launch custom video player for UIWebView?

iOS embed video, video still plays when in another view

So lets say I have a UIWebView on my view, embed with a YouTube video. The view is connected to a navigation view controller. This means that when i click a button it pushes a view on to the stack. But when I play the youtube video and go to the next view. The video is still playing. Is there anyway to handle stopping an embed youtube video when going to another view?
What if I have multiple cells with a UIWebView embed with a YouTube video in a UICollectionView? I don't have reference to all the UIWebViews to set to nil. (Sorry for the confusion previously above)
What I do is just set the UIWebView's content to nil when I'm moving to another page, which removes the video player completely, but if you just want to pause the video so the user can resume when they come back, you'll have to talk to the youtube player using javascript. See How to Pause Media Playback in UIWebView for one approach.
If you use Youtube Javascript api to play the video - you can pause it when leaving current view with
-(void)viewWillDisapper:(BOOL)animated
{
[super viewWillDisappear:animated];
[webView stringByEvaluatingJavaScriptFromString: #"player.pauseVideo();"];
}
You need to load a blank page into the UIWebView to stop the video playing. Here's a quick way to do it:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated]
[yourWebView loadHTMLString:nil baseURL:nil];
}

Play a list of media (video/audio) items on iOS

I'm developing an iPhone App and I need to implement a player to play a list of media (video/audio) items.
Following is a screenshot of player I have captured from an another iPhone app, I found many apps playing video/audio using a player has similar UI like this.
Can this player (including UI) can be implement by official API? Or just implement manually?
How can I implement a same player like this?
To Play audio follow this blog
And to play video, either you can use CustomMovieplayer or go with UIWebView with embedded html.
Movie Player sample code from here
To play video as embedded html in UIWebView, check this..
https://stackoverflow.com/a/7551375/790794
As per the file type, you can modify the source type.

Resources