No UI controls for MPMoviePlayerController - iphone

I'm trying to add a video that I pull from my server do play in my app.
The video plays now, but I don't have any UI controls for volume. fullscreen etc.
Can any one help? Here is my code
NSURL *url = [NSURL URLWithString:#"http://www.gzerodesign.com/sharksclips/video.mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlModeDefault;
moviePlayer.shouldAutoplay = YES;
[[moviePlayer view] setFrame:[[self view] bounds]];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer play];
} else {
// Use the old 2.0 style API
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
}

I only have experience the New 3.2 style API.
moviePlayer.controlStyle = MPMovieControlModeDefault;
comment out
// moviePlayer.controlStyle = MPMovieControlModeDefault;
you may be have fullscreen button and skip button.
but not show volume.
I did not try but, I search this.
MPMoviePlayerViewController not showing volume slider?

Delete this line in your code:
moviePlayer.controlStyle = MPMovieControlModeDefault;
& also this line:
moviePlayer.movieControlMode = MPMovieControlModeHidden;
& then check.

Related

how to play a video on startup of the app or on viewdidload with done button?

I have been able to successfully play a video on start of the app by calling a function that plays the video in the viewDidLoad method. But on doing so, i am unable to see the "Done" button. The "Done" button only seems to appear if i call that same function with the help of a button. I am posting the code below. How will I make this done appear by calling the same function in the viewDidLoad method? What have i been doing wrong? Thank you!
in my viewcontroller.m file
- (void)viewDidLoad
{
[super viewDidLoad];
[self playMedia];
}
- (void) playMedia {
//hide status bar first
[[UIApplication sharedApplication] setStatusBarHidden:YES];
//resets again in playMediaFinished
movieFile = [[NSBundle mainBundle] pathForResource:#"sec" ofType:#"mp4"];
NSURL *url = [NSURL fileURLWithPath: movieFile];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playMediaFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
[moviePlayer setFullscreen:NO animated:YES];
[self.view addSubview:moviePlayer.view];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
CGAffineTransform transform = self.view.transform;
[moviePlayer.view setFrame:CGRectMake(0, 0, 480, 320)];
moviePlayer.shouldAutoplay = YES;
NSLog(#"Should be playing Movie");
}
- (void) playMediaFinished: (NSNotification*) theNotification {
moviePlayer = [theNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
if ([moviePlayer
respondsToSelector:#selector(setFullscreen:animated:)])
{
[moviePlayer.view removeFromSuperview];
[playerView removeFromSuperview];
//reset status bar
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
NSLog(#"Should be DONE playing Movie");
}
Try doing this using viewDidAppear instead of viewDidLoad. I'm not surprised starting a video in viewDidLoad is causing unexpected behavior considering you're presenting the video before the main view appears on screen. Keep in mind, the view is done loading before it is actually visible.

youtube embbed videos iphone

I'm trying to play a YouTube video within an iPhone app using the technique in this URL http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
The technique works fine and the video plays fine, except that i want the video to switch back to the main view when its finished. when i click on "done" button of the youtube player it does turn back to the main view but when the video is finished the youtube player doesn't disappear(you have to click "done")
Please help!
NSURL *url = [[NSURL alloc]initWithString:#"url for video"];
self.backgroundColor=[UIColor redColor];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer.view setFrame:CGRectMake(0,0,self.frame.size.width-10,self.frame.size.height-10)];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay=YES;
moviePlayer.repeatMode = NO;
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer prepareToPlay];
pause=NO;
[self.view addSubview:moviePlayer.view];
You can use notification to inform when its finished so that you can remove it from the view and let previous view on screen.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.player.moviePlayer];
Don't forget to remove notification in moviePlaybackComplete: by
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];

IPhone Frame Video Playing

I have written this piece of objective-c code for playing a video after touching an image.
//start video here
NSString *path = [self localVideoPath:NO];
// Create custom movie player
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithPath:path] autorelease];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(onMSAASDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setFullscreen:FALSE];
//---play partial screen---
moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
//[[moviePlayer view] setFrame: [image bounds]];
[self.view addSubview:moviePlayer.view];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
// Prep and play the movie
[moviePlayer play];
The problem is that the code stops working at second line of statement. The error is... Program GDB: Received Signal: "EXC_BAD_ACCESS"
Help Me Please!
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithPath:path] autorelease];
the function initWithPath is not the part of MPMoviePlayerController class,
i could not find it in documentation.
May be you were trying to use
- (id)initWithContentURL:(NSURL *)url
plz read the apple documentation.
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

iOS4 MPMoviePlayerController Embedding

I am using MPMoviePlayerController currently to play a video inside IPhone and now I wish to play this video in a small area of the view (not the full screen). I think there is a frame way of doing it but I couldn't find the required tutorial somewhere. Have you been across any? That would be great.
UPDATED
I have reached to this point but still it doesn't show the player to play on screen.
-(IBAction)startVideo {
//start video here
NSURL *path = [[NSURL alloc] initWithString:[self localVideoPath:NO]];
// Create custom movie player
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:path] autorelease];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setFullscreen:FALSE];
// May help to reduce latency
[moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(onMSAASDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
//---play partial screen---
//moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
moviePlayer.view.frame = image.frame;
//[[moviePlayer view] setFrame: [image bounds]];
[image removeFromSuperview];
[self.view addSubview:moviePlayer.view];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
// Prep and play the movie
[moviePlayer play];
}
Here is 'windowed' code...
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[player setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player setScalingMode:MPMovieScalingModeAspectFill];
[player setFullscreen:FALSE];
//---play partial screen---
player.view.frame = CGRectMake(0, 0, 200, 300);
[self.view addSubview:player.view];

playing intro movie on ipad

i am trying to play an intro movie (like a splash screen). it used to work fine for sdk 3.0 but now i am doing it for iPad. and its not running movie instead it just show black screen before view appears.
here is my code
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"m4v" inDirectory:nil];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.fullscreen=YES;
moviePlayer.view.frame = CGRectMake(0, 0,1024,768);
[moviePlayer setShouldAutoplay:YES];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setRepeatMode:MPMovieRepeatModeNone];
[moviePlayer prepareToPlay];
[moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
return YES;
}
and here is my moviePlaybackDidFinish
- (void) moviePlaybackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
theMovie.initialPlaybackTime = -1;
[theMovie pause];
[theMovie stop];
[theMovie release];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
i dont know what i am missing here?
thanks for any help....
UPDATE i just found out that it plays sound but no video....is this obvious?pls help
As you're using MPMoviePlayerController over MPMoviePlayerViewController I think you need to be adding the player's view to your view hierarchy before calling play, as per the docs:
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view]; //add the player' view
this might explain why you're hearing audio but not seeing anything, pretty sure you need to setup the app window first too ([window makeKeyAndVisible]; etc)