IPhone Frame Video Playing - iphone

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

Related

No UI controls for MPMoviePlayerController

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.

How do you play a movie in an iphone app?

I want to add a movie at the beginning of my iphone app. I have watched the tutorials and this is the code I have come up with. Why won't it work. I don't even see a movie. I call it from the viewDidLoad function of my ViewController with the following code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"BTS Intro" ofType:#"mov"];
[self playMovieAtURL:[NSURL fileURLWithPath:path
-(void)playMovieAtURL:(NSURL *)theURL {
MPMoviePlayerController *thePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
thePlayer.scalingMode = MPMovieScalingModeAspectFill;
thePlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:thePlayer];
[thePlayer play];
}
-(void)myMovieFinishedCallback:(NSNotification *)aNotification {
MPMoviePlayerController *thePlayer = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:thePlayer];
[thePlayer release];
}
You initiated playing of a movie but didn't add [thePlayer view] into views hierarchy that is why you do not see anything. Take a look at description of this operation in apple docs:
When you add a movie player’s view to your app’s view hierarchy, be sure to size the frame correctly, as shown here:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
MPMoviePlayerController Class Reference

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)

Want to play video but there´s only sound, no visible content

i have a tabbar based application with 2 tabs. One to show images and the other to show videos. If i click on the video tab, different thumbnails are showing up. If i click on one of these images, i would like to push that videoviewController to play a video in another navigation view - if i turn the iphone around, it will play fullscreen. So, actually its the same functionality like the original "photo"- app.
What i´ve got so far is a scrollview with different buttons where i added a backgroundimage. By clicking on one of these buttons, i´ve added the button-functionality:
[myButton addTarget:nil action:#selector(buttonDown: ) forControlEvents:UIControlEventTouchUpInside];
And here´s my "buttonDown"-method:
-(void) buttonDown:(NSString*) sender {
moviePlayer = [[MoviePlayer alloc] init];
[self.view addSubview:moviePlayer.view];
NSLog(#"MoviePlayer: %#", moviePlayer);
[self.navigationController pushViewController:moviePlayer animated:YES];
[moviePlayer release];}
Here´s my "MoviePlayer.m"-file:
- (void)viewDidLoad {
UIView* imageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100 )];
imageView.backgroundColor = [UIColor greenColor];
[self.view addSubview:imageView];
[imageView release];
NSString *url = [[NSBundle mainBundle] pathForResource:#"testmovie" ofType:#"mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
//player.scalingMode = MPMovieScalingModeAspectFill;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player play];
[super viewDidLoad];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player autorelease];
}
So the navigation works great - by clicking on a button, the view is pushed (and i get my green test-uiview) and the sound of that video file is been playing - but no video is visible, only that sound.
I´ve no idea - if i test that code in a new viewbased-project-template it works great. So i think there some problems with the views.
Any ideas on that?
Would be great. Thanks for your time.
Give this a go:
[player setFullscreen:YES];
[self presentMoviePlayerViewControllerAnimated:player];
I believe that should resolve your woes! Please vote for answer if it assists!