i cannot see movie playing in iphone simulator - iphone

i have created a application that plays movie on button click..my application is running without any warning or error. But i am not able to see the movie don't know why?
I have added the Media player framework and also imported the #import in viewController.h
my button action code is as follow...
-(IBAction)playMyMovie:(id)sender{
NSBundle *bundle =[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"jumps" ofType:#"mov"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie =[[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
}
Please tell me what i am missing..

in iPhone simulator you could not play movie properly.
test the applcation on iPhone (Real instrument).
It will work fine.

You are creating a MPMoviePlayerController. It has a view property - that is its view. It is your job to put that view into your interface. If you don't, you won't see anything.

try add this line before the [theMovie play]
[self.view addSubview:theMovie.view];
and also remember to setFullScreen:
[self.theMovie setFullscreen:YES];
if you dont want fullscreen but want to embed into the view, you can ignore the "setFullscreen", but set the frame for the MPMoviePlayerController view:
[self.theMovie.view setFrame:CGRectMake("add in the size you want here")];

Related

How to add videoPlayer as an subview?

Hello I am facing an problem related to adding subview;
I am following the Code:
NSString *urlStr = [NSString stringWithFormat:#"http:x/iphone0.m3u8"];
NSURL *videoURL = [NSURL URLWithString:urlStr];
MPMoviePlayerController *iVideoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:videoURL];
[self.view addSubview:iVideoPlayer.view ];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// The device is an iPad running iPhone 3.2 or later.
iVideoPlayer.view.frame = CGRectMake(353,258,320,240);
}
else
{
iVideoPlayer.view.frame = CGRectMake(156,96,168,148);
}
[iVideoPlayer play];
In this code I like to add an video player as an subview . I have successfully add the videoPlayer.but problem is that during the video playing ,if i click on the specified area (CGRectMake(353,258,320,240);the video stop. I like apply the videoPlayer Function (next,Pause,Volume up/Down)which are not done .
How to resolve this .?
You have some options for the control style of your MPMoviePlayerController instance. By setting the controlStyle property to one of the following options, you can enable certain player controls (like pause, play, etc).
MPMovieControlStyleNone,
MPMovieControlStyleEmbedded,
MPMovieControlStyleFullscreen,
MPMovieControlStyleDefault
The descriptions for the above styles can be found here: MPMoviePlayerController Class Reference
Here is an example of how to set this property.
[iVideoPlayer setControlStyle:MPMovieControlStyleEmbedded]

Iphone : Video playing at startup doesn't quit

i made a video playing when my app loads however it doen't quit after playing even if you prees "Done". What am i doing wrong?
- (void)viewDidLoad {
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"Video Logo Final" ofType:#"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0);
[self.view addSubview:theMovie.view];
[theMovie play];
[super viewDidLoad]; }
Also, i made a try to put the same code in "application didFinishLaunchingWithOptions" but i get a warning at "[self.view addSubview:theMovie.view];"
Ay ideas about that?
p.s. As you probably guessed i am very new to programming, any help would be really appreciated...
Basically you need to register for a notification.
The way I do it is:
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
Change the parameters to fit however it should in your app.
Here's the documentation for the MPMoviePlayerPlaybackDidFinishNotification.
Also, if it's not "quitting" after playing (even when hitting the "Done" button), it sounds like you need to remove the theMovie MPMoviePlayerController and associated view from the view you originally added it to.

iOS - Force full screen video

I'm using a MPMoviePlayerViewController. When the video loads and starts playing it doesn't fill up the whole screen. I have to press the full screen button at the top right to make that happen. If I use MPMoviePlayerController I can't get it to fill the screen at all.
Any way via code that I can get my video full screen using the MPMoviePlayerViewController without having to press the fullscreen button?
I know i'm using a private API here, but thats ok, it is for a demo.
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:#"phatpad" ofType:#"mov"];
if (moviePath)
{
NSURL *url = [NSURL fileURLWithPath:moviePath];
player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
}
player.view.frame = self.view.frame;
[self.view addSubview: player.view];
}
Here is a screen. The first is without pressing the full screen button, the second is after pressing it.
You have to set the fullscreen attribute to true and the scallingMode to the aspect fill like this:
if (moviePath)
{
NSURL *url = [NSURL fileURLWithPath:moviePath];
player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
player.moviePlayer.fullscreen = YES;
player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
}
I have tested at home and it works, so I hope to you too.
On iPhones and iPod Touches, MPMoviePlayerController plays in full screen no matter what, so I'm assuming you're talking about an iPad? Can we please see some code samples? I can make mine full screen simply by resizing the UIView in my XIB file. How are you trying to do it?

Help stopping audio using AVAudioPlayer

Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file in .caf format. What I'm trying to do is have a play and pause button. Here is a sample of a simple IBAction to play the audio from a button.
- (IBAction) clear {
NSString *path = [[NSBundle mainBundle] pathForResource:#"clear" ofType:#"caf"];
AVAudioPlayer* myAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
myAudio.delegate = self;
myAudio.volume = 1.0;
myAudio.numberOfLoops = 0;
[myAudio play];
}
So when I go ahead and create another IBAction with the method...
- (IBAction) stopaudio {
[myAudio stop];
audioPlayer.currentTime = 0;
}
I compile and xcode tells me that myAudio in the stopaudio IBAction is not defined. How do I fix it so I'm able to access myAudio in another IBAction?
My Second question is that I'm using NavigationController to setup a TableView, when I make a selection it takes me to a UIView with a back button to go back to the TableView. What I'm trying to do is to kill any audio that I have playing in the UIView when I go back to the TableView. The code above is part of the code that I'm going to have in the UIView.
Also one quick question. Lets say I have an audio file that is 1 minute long. Clicking play again will overlap a new instance of that audio before the old instance is done playing. How can I check to see if myAudio is playing and not allow it to be played again until myAudio is finished playing?
Thank You!
First of all, you should read the documentation. It will remove almost all of your questions. Nevertheless, to have access to your instance of AVAudioPlayer from all methods of your class, you should define it in your .h file. To stop your player on returning to the previous screen, call [myAudio stop] in your viewWillDisappear:(BOOL)animated method. About your last question. If you define myAudio in your .h file, you will be able to check if it is playing now. smth like
- (IBAction) clear {
if(![myAudio isPlaying]){
[myAudio play];
}
}

Embedded Video in a UIView with iPhone

I would like to write an app that downloads (or streams) a video (encoded as required) in a view. I dont want to use the MPVideoPlayer from the SDK as it opens the video in full screen. I would like to place another UIView (transparent) over the video so that my users can annotate over the video.
Anyone have any idea or can point me to some code that will play video in a UIView?
If you want to do this you will need to include your own (software) video decoder, which will not have access to the hardware acceleration on the system. Even if you can get it working with acceptable performance it will be a huge battery drain.
If you wish to play a video in portrait mode, I have solution for that.
If you think that -MPMovie Player can run under a view, according to me it's not possible.
MP Movie player will work as Apple has designed.
So, MP Movie player will always / almost run in full screen.
Solution for portrait mode.
#interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
#end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
Hope that will help to you.
See, My question is very similar like yours.
playing video in custom size screen - view in iphone
Try this:
UIViewController *v = [[UIViewController alloc] init];
v.view.backgroundColor = [UIColor orangeColor];
NSString *path = [[NSBundle mainBundle] pathForResource:#"demo" ofType:#"mp4"];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(#"cannot find %# in bundle or doctuments", path);
}
NSURL *url = [NSURL fileURLWithPath:path];
MoviePlayerViewController *mpvc = [[MoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mpvc.moviePlayer];
mpvc.moviePlayer.fullscreen = NO;
[mpvc.moviePlayer setControlStyle:MPMovieControlStyleNone];
mpvc.moviePlayer.view.frame = CGRectMake(10, 100, 300, 300);
[v.view addSubview:mpvc.moviePlayer.view];
[mpvc.moviePlayer play];
[self presentModalViewController:v animated:YES];
[v release];
Maybe you should check the MediaPlayer's private headers, and simply add the video's view as your view's subview.