iPhone app:MpMoviePlayer not playing movie in iPad with ios5 - iphone

I have created my iPhone app in Xcode 4 with base SDK 4.3
In my iPhone app I have used MPMovieplayercontroller and using that I am playing Video
It is playing my video file in my iPod Touch with IOS 4.3 but if I install same project in my iPad with iOS 5, it is showing black screen only but not playing video.
what could be wrong?
Here is the code
in .h file
MPMoviePlayerController *moviePlayer;
in .m file
-(void)playVideo{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"testbild1" ofType:#"m4v"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
[self.view addSubview:testview];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}

It doesn't look like you're setting autoplay
shouldAutoplay
A Boolean that indicates whether a movie should begin playback automatically.
#property (nonatomic) BOOL shouldAutoplay
So like:
moviePlayer.shouldAutoplay = true;
You should also be probably calling prepareToPlay and play from the MPMediaPlayback protocol that MPMoviePlayerController implements
Old Post (should have been a comment):
What version iOS? iOs 5.1 beta just came out and alters how MPMoviePlayerController works.
You can get details on Apple's iOS beta site but I can't print them here YAY EULA.
EDIT
Now that the OS is public, here's the relevant documentation (registration -- you might have to pay the $100 as well, I forget...)
iOS 5.1 Release Notes (Search for prepareToPlay on that page -- no deep linking)
MPMoviePlayerController class documentation

Related

iphone, ipad VGA External Display - tvOutManager

i used all the examples and source code out there for displaying application content to external VGA display. while playing video in inside of the application am getting bellow thing in external device. any suggestion.... am i missing somthing.. but in device it showing actual window in fine way..
Hello All here am answering to my own question.
robterrell's TVOutManager will not play any video to external device by simply doing [[TvOutManager sharedinstance] startTvOut] and [[TvOutManager sharedinstance]s topTVOut];
here we have add the instance of player to tvoutWindow.
[tvoutWindow addSubview:player's instance];
but here thing is the video is not displayed in device,
but you can control external window player from device.
cheers.
NSString *url = [[NSBundle mainBundle] pathForResource:#"Overview" ofType:#"mov"];
player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedCallback:)name:MPMoviePlayerPlaybackDidFinishNotification object:player];
//---play partial screen---
player.view.frame = CGRectMake(35, 450, 430, 300);
[self.view addSubview:player.view];
[player play];
- (void) movieFinishedCallback:(NSNotification*) aNotification {
[[TVOutManager sharedInstance] startTVOut];
player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
}
this the code am added in mainviewController class in robterrell's TVOutManager sample application. after connecting device into external device. while switching mirror video on am not getting anything..

video plays but no picture - just sound?

Edit: if you come across this and want to know how I eventually solved it I gave up on that code below eventually and did this:
-(void)playMovieAtURL:(NSURL*)theURL{
mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.view.backgroundColor = [UIColor blackColor];
}
Original post:
This is my code - I took it off the apple site so shouldn't be a problem.
It runs in a UITableViewController on the didSelectRowAtIndexPath method.
When you select the row the video starts playing - the sound outputs at least - but there's no picture. Any idea why this is? I have included the framework.
The video is one off the apple website (a facetime video) that I used for testing.
-(void)playMovieAtURL:(NSURL*)theURL{
MPMoviePlayerController* theMovie =
[[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.controlStyle = MPMovieControlStyleNone;
// Register for the playback finished notification
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: #selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
The behaviour of MPMoviePlayerController changed in OS 3.2 - you need to explicitly add the movie player's view to your view hierarchy now - using something like:
[aView addSubview:moviePlayerController.view];
moviePlayerController.view.frame = aView.frame;
Alternatively you can use an MPMoviePlayerViewController (new in 3.2) to manage the view.
If you're targetting both pre- and post-3.2 devices (e.g. iOS 3.1 and 4.0) then you'll need some conditional code to determine the OS the code is running on and handle accordingly. I've used this in previous projects:
if ([moviePlayerController respondsToSelector:#selector(setFullscreen:animated:)]) {
// Running on OS 3.2 or above
// Code to add to a view here...
}

Writing an app to stream video to iPhone

I'm interested in creating an iPhone app that can stream video from a central server, YouTube style. I was wondering if anyone has ever tried to do this before, what is the path of least resistant, existing APIs, etc? I really know nothing about how this is generally done. Would I be working with sockets? Just looking for some direction here. Thanks!
If you have the streaming server up and ready, it is quite easy to implement a video controller that pops up youtube-style.
NSString *videoURLString = #"http://path-to-iphone-compliant-video-stream";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
You need to handle the controller that display the video player's view (which is self in this case).
In iOS 3.2+ MPMoviePlayerViewController make it even easier:
NSString *videoURLString = #"http://path-to-iphone-compliant-video-stream";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
presentMoviePlayerViewControllerAnimated is a MediaPlayer's additional method to FWViewController that you will find in iOS 3.2+ and it takes care of creating a view controller and pushing it on the stack, animating it with a slide-from-bottom animation, as in youtube.app.
Apple has a detailed article about setting up server side for media streaming:
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html
and Best Practices Note:
https://developer.apple.com/library/content/technotes/tn2224/_index.html
Not only it contains info about streaming service architecture and tools used to build it but also has some requirements to such kind of service that must be fulfilled and references to live test streams.
Use this code to use low memory. On streaming video....
-(IBAction)playMovie:(NSURL *) theURL
{
NSURL *fileURL = theURL;
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.useApplicationAudioSession = NO;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
QuickTime videos already stream to the phone. The path of least resistance would be to use the media player controller and point it to a streaming media file on a streaming server.
While the existing answers are good, if you need to use non HTTP streams (mms or rtmp for example) or non Apple supported audio / video codecs, things get a bit more complicated.
I'm not an expert myself, but I've been using this VideoStreaming SDK to solve those problems, and it makes customizing the client much easier (background streaming, pausing streams, etc). Might be worth a look if you have those requirements as well.
2018 answer You can use AVPlayerViewController since MPMoviePlayerController is deprecated since iOS 9
NSURL *url = [NSURL URLWithString:videoUrl];
_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:url];
_playerViewController.player.volume = 1;
_playerViewController.showsPlaybackControls = YES;
_playerViewController.view.frame = CGRectMake(....);
[self.view addSubview:_playerViewController.view];

i cannot see movie playing in iphone simulator

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")];

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.