I try to set userinteractionEnabled: to NO for an AVPlayerViewController
[playerViewController setUserInteractionEnabled:NO];
but I have an error
"No visible #interface for 'AVPlayerViewController' declares the selector 'setUserInteractionEnabled:'"
No visible #interface
Here is my complete code:
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
playerViewController.showsPlaybackControls = false;
[playerViewController.player play];
[playerViewController setUserInteractionEnabled:NO];
[self.navigationController pushViewController:playerViewController animated:YES];
[self performSelector:#selector(popToMain) withObject:nil afterDelay:durationInSeconds];
I just would like the people cannot click on the screen during the video.
Thanks in advance.
Maybe this might help you:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
Try this:
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
or this:
playerViewController.view.userInteractionEnabled = NO;
Related
If I hit below url in browser, it plays video but my below code is not playing it on iPhone.
http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4"]];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
this is the screenshot of the iPhone.
MPMoviePlayerController is deprecated. You can use AVPlayer instead.
AVPlayer *player = [AVPlayer playerWithURL:"URL"];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];
You need to tell the MPMoviePlayerController that it needs to stream the video. Just add the following line:
moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
yes , you have to tell its streaming url as :
moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
then prepare to play
[moviePlayer prepareToPlay];
I'm using AVPlayerViewController with the UINavigationController like following code.
AVPlayerViewController* audioPlayer = [[AVPlayerViewController alloc] init];
audioPlayer.audioFilePath = recordFilePath;
[self.navigationController pushViewController:audioPlayer animated:YES];
When the AVPlayerViewController appeared, the progress slider had been hidden by the UINavigationBar control.
How can I show the progress slider along with the UINavigationBar?
Try to set the navigation bar's translucent property to "NO" in your viewDidLoad
self.navigationController.navigationBar.translucent = NO;
It will start the view from being framed underneath the navigation bar and status bar. Hence you can see AVPlayerViewController progress slider.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
[self performSelector:#selector(PlayVideo) withObject:self afterDelay:1.0];
}
-(void)PlayVideo
{
NSURL *videoURL = [NSURL URLWithString:#"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self.navigationController pushViewController:playerViewController animated:YES];
}
The progress slider will shown at the bottom of the device
I have used MPMoviePlayerController to play video in my web view from a live url
but when i pop the view controller so at that time the black screen appears in the view and the navigation bar title changes as it should be.
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *movieURL = [NSURL URLWithString:self.url];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.contentURL = movieURL;
if (self.moviePlayer)
{
[self.moviePlayer prepareToPlay];
self.moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
// save the movie player object
[self.moviePlayer setFullscreen:YES];
[self.moviePlayer setShouldAutoplay:YES];
[self.moviePlayer setAllowsAirPlay:YES];
// Play the movie!
[self.moviePlayer play];
[self initializeNavigationController];
}
}
-(void)initializeNavigationController
{
UIBarButtonItem *buttonBack = [[UIBarButtonItem alloc] backButtonWithtarget:self action:#selector(Back)];
self.navigationItem.leftBarButtonItem = buttonBack;
}
-(void)Back
{
[self.moviePlayer.view removeFromSuperview];
[self stopLoadingVideoInView];
[self.navigationController popToRootViewControllerAnimated:YES];
}
Live video screen
After Back button press
I think you just remove [self.view removeFromSuperview]; and replace with
[self.moviePlayer.view removeFromSuperview];
I solved it finally
In app delgate i created a method to allocate memory to vc again
- (void)resetAppToFirstController
{
UIViewController *obj = [[MainMenuViewController alloc] init];
//Create Navigation Controller to Hold View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self.window setRootViewController:navigationController];
}
and on my back button action
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.resetAppToFirstController;
This solved my issue it may help some one for MPMoviePlayer
In case you are added youMovieController as sub view of parent view, use this method to remove it.
[self.view removeFromSuperView]
In case you are pushing viewController via UINavigationController, just call this to go back.
[self.navigationCotroller popViewController:animated]
In case you are present ViewController, use this to remove it.
[self dismissViewController]
remove [self.view removeFromSuperview]; and replace with [self.moviePlayer.view removeFromSuperview];
- (void)resetAppToFirstController
{
UIViewController *obj = [[MainMenuViewController alloc] init];
//Create Navigation Controller to Hold View Controller
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:obj];
[self.window setRootViewController:navigationController];
}
I am trying to play movies from a view controller. I am using the code below to do that:
VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:#"videoPlayerController"];
moviePlayer.view.frame = rect;
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[window.rootViewController presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:items];
Normally it works fine. But sometimes, movie starts but I cannot see the video, just I can hear the sounds.
What is the best way to play video on top of everything?
NSString *path = [[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
Another solution would be to segue to another ViewController and dissmiss it when the movie ends.
You can also try using AVPlayer. In that case, you can play the video in your current view itself without having a separate overlay for the video.
Here's an example of playing multiple AVPlayers. You can modify the code to play a single video.
I have an iPad application that creates and shows a video with an MPMoviePlayerViewController. Here's my code:
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:URLEncode(uri)]];
[mpvc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[mpvc setWantsFullScreenLayout:YES];
[<MainViewController> presentModalViewController:mpvc animated:YES];
Movie load/playback works fine, however, when the Movie Controller appears, it shows the status bar (connection, battery, hour) at the top, even when I have it deactivated on my main window.
I've tried doing:
[mpvc setWantsFullScreenLayout:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And nothing seems to work, HOWEVER if I also put:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
The status bar disappears! But the Movie Controller still gets resized as if the status bar is there (even when I already used -setWantsFullScreenLayout:).
Can someone point me to an easy (proven) way to show the video without the status bar?
Thanks.
Just realised the question was iPad-specific. My code was for the iPhone, but some of it may help you anyway.
I had to do this a couple days ago, I think your issue is simply not calling hide on the status bar after the video starts playing. Either way I have the tried and tested code here which works from 3.0 to 4.2:
- (IBAction) playIntroVideo
{
NSString *videoString = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
_player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
if
(
[_player respondsToSelector:#selector(view)] &&
[_player respondsToSelector:#selector(setFullscreen:animated:)] &&
[_player respondsToSelector:#selector(setControlStyle:)]
)
{
[[_player view] setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT_FULL)];
[_player setFullscreen:YES animated:YES];
[_player setControlStyle:MPMovieControlStyleNone];
[self.view addSubview:[_player view]];
}
[_player play];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(terminateVideo)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBarHidden = YES;
}
- (void) terminateVideo
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.navigationController.navigationBarHidden = NO;
if ([_player respondsToSelector:#selector(view)])
{
[[_player view] removeFromSuperview];
}
_player = nil;
[_player release];
}
The answer to this question has an error at the end:
_player = nil;
[_player release];
These should be reversed:
[_player release];
_player = nil;
Messaging nil with release has no effect.
You can set UIStatusBarHidden in your plist, that should solve it :)