I am using YTPlayerView to play YouTube videos inside my app. I need to do some customization that instead of using YTPlayerView button I want to create my own buttons to control the playing view and also I want to handle it by my self that when the video will go to full screen.
I know that we can also use UIWebView. I there is some way that I can do the same thing using UIWebView then I can also do that.
Is there any way that I can do this or YouTube is providing a common way to play videos which we see in many other applications.
So what exactly is your question? Are you looking to create you own buttons to start the video, stop the video, and make the video full screen?
YTPlayerView *playerView = ...
// ...
- (IBAction)playButtonPressed:(id)sender {
[playerView playVideo];
}
- (IBAction)pauseButtonPressed:(id)sender {
[playerView pauseVideo];
}
- (IBAction)stopButtonPressed:(id)sender {
[playerView playVideo];
}
There is a discussion on the GitHub page about playing a video full screen programmatically: https://github.com/youtube/youtube-ios-player-helper/issues/35
Related
I'm using https://github.com/youtube/youtube-ios-player-helper for implement Youtube videos in my iOS Project.
I implement the YTPlayerView object in Appdelegate; in my ViewController I execute the view. Really YTPlayerView, is a UIView that show an UIWebview.
The proble occure when I want to listen the webview (Youtube Music) in background.
- (void)applicationDidEnterBackground:(UIApplication *)application{
[self.playerView playVideo];
}
I implement this in Appdelegate but the first time I dismiss the app, the music is set in background, but the second time no and I don't know why.
I have seen so many apps at app store that u can make this, so is possible but I don't have seen anything about it.
Thanks
I am using UIWebView in an iOS app to play YouTube videos but to provide native experience, I've implemented playback controls using UIKit. So the UIWebView is only used to display video.
I've also implemented -remoteControlReceivedWithEvent: to allow control from Control Center and controller buttons on earphones. But it seems that UIWebView automatically handles remote control events from the earphones. This is a problem because when you toggle play/pause, my code would pause the video and then UIWebView will toggle it again to play the video.
Is there anyway to prevent this from happening?
Related issue is that UIWebView tries to set "Now Playing" information to MPNowPlayingInfoCenter which is also done by my code.
I encountered same kind of issue with my app which playbacks audio using AVAudioPlayer.
This app displays current audio info in MPNowPlayingInfoCenter during playback.
My requirement was to display an html5 video advert (with audio) inside a webview on top my player.
First i used only UIWebView as i needed to support iOS7 but i met a lot of issues, one of them was MPNowPlayingInfoCenter that displays url of ad video in place of current native audio playback.
I tried several solutions such as method swizzling on UIWebView without any success.
I found only one solution that works for me: use WKWebView by default instead of UIWebView web container. HTML5 video playback will not interact anymore with MPNowPlayingInfoCenter, i had to support also iOS7 so i created a wrapper class to switch between UIWebView (with still the issue) on iOS7 and WKWebView from iOS8 and more.
Hope this helps.
I ran into this question while trying to solve somewhat the reverse problem: I added a UIWebView to an app and remote control events were not working when the UIWeb view was on display, but worked elsewhere in the app.
In my case the solution was to add these 3 methods, which are present on all other view controllers in my app, to the controller of my new UIWebView:
- (void) viewDidAppear:(BOOL)animated {
[self becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self resignFirstResponder];
}
-(void)remoteControlReceivedWithEvent:(UIEvent *)event {
// Logic to handle remote control events
}
From this, I suspect that you can prevent your UIWebView from handling remote control events by doing one of two things:
1. Include logic in the remoteControlReceivedWithEvent to ignore the remote control events you don't want handled.
2. Have your UIWebView resign being the first responder by calling resignFirstResponder in the viewDidAppear method of the controller.
I'm finding it difficult to search for this, background video searches for iOS typically refer to multitasking and switching apps with video.
I want to know if it's possible to have a video playing full screen without movie player controls, while displaying another view on top of that with logo, buttons, text, etc...
So,
Background: 15 second video loop -
Foreground: login / signup buttons, logo, etc...
There are a number of options, but the simplest will be to use a MPMoviePlayerController, with its repeatMode property set to loop forever, and its controlStyle set to none. That will give you a view with a looped movie with no controls that you can use as a background by adding it to your view hierarchy.
OP here - I was able to display a video full screen using this code (in viewDidLoad):
(don't forget to substantiate player as a property with MPMoviePlayerController *player;)
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"videoname" ofType:#"m4v"]]];
[player.view setFrame: self.view.bounds];
player.repeatMode = MPMovieRepeatModeOne;
player.controlStyle = MPMovieControlStyleNone;
[myView addSubview:player.view];
[player play];
And that worked fine - it displays a video fullscreen without video controls. What I had a problem with was displaying buttons and graphics above that. Even though my view hierarchy had the player.view seemingly behind my view with buttons, I couldn't get the buttons to appear.
I fixed that by adding in:
[player.view addSubview:overlayView];
Just set the layer you intend to display above the video to an IBOutlet and then use the video view to add that view (overlayView in this case) as a subview.
I actually prefer a way that is portrayed in this tutorial
basically the idea is to create a gif of your video, crop it to iPhone Screen size and load it into an un-interactive UIWebView. I believe this will get the job done if you don't need any audio, and it's basically done effortlessly.
I hope it helps you =)
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];
}
In my iPhone app I have designed a custom video player, currently it is very basic with just a play pause and stop button,
but I would like the user to be able to scrub, (I think thats the right word) the video like you can do with apple's original media player.
So for Instance I would like to be able to take a UISlider and have it control the current postiion of the videos playback if you get what I mean. Oh and incase your curious, the way I pause/play/stop the video is by using this simple piece of code [self.theMovie play]; [self.theMovie stop]; [self.theMovie pause]; The trouble is I don't know how to scrub the video.
Any help appreciated.
I've asked the same question: customize quicktime iphone and here MPVideoPlayer add/remove buttons
It seams that you have to posibilities:
You can add you view over the main window. An sample can be found here: MoviePlayer Sample
You can iterate through views, found one you need and Add/Remove views. I don't know yet how must does Apple likes/dislikes this method.