Reputation: 1252
I'm using MPMoviePlayerController to play a ".3gp" video , i get the data from the server and save it in NSData object then i write it to a file inside the Document directory here's my code
in .h i defined videoPlayer as
@interface MainViewController : UIViewController {
MPMoviePlayerController* videoPlayer; }
@property (strong, nonatomic) MPMoviePlayerController* videoPlayer;
in .m file
-(void)videoWillStartPlayWithUrl:(NSData *)d
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myMove.3gp"];
[d writeToFile:path atomically:YES];
NSURL *url = [NSURL fileURLWithPath:path];
adBannerView.hidden = YES;
self.videoPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
self.videoPlayer.controlStyle = MPMovieControlStyleEmbedded;
self.videoPlayer.shouldAutoplay = YES;
[self.videoPlayer.view setFrame: self.view.bounds];
[self.view addSubview:self.videoPlayer.view];
[self.videoPlayer setFullscreen:YES animated:YES];
[self.videoPlayer prepareToPlay];
[self.videoPlayer play];
}
it's working perfectly in iOS < 5 but in iOS 5 it just shows a black screen and quit directly and i can't seem to figure the problem that prevent the video from playing in iOS 5 any help is much appreciated
Upvotes: 1
Views: 2032
Reputation: 1252
After many hours of searching and debugging the problem turned out to be related to the codecs of the videos i was trying to play ,
while they worked perfectly in iOS 4 , iOS 5 requires the special codecs of the .3GP videos as mentioned in the MPMoviePlayerController. programming guide , so the solution was to change the codec of my videos and the code worked perfectly on iOS 5
Upvotes: 1
Reputation: 6166
In Your header file do this :-
MPMoviePlayerController *myPlayer;
and change your property to :-
@property(nonatomic, strong) MPMoviePlayerController *myPlayer;
Initiate the moviePlayer as follows :-
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:Url];
self.myPlayer= player;
You might have your arc enabled.
Upvotes: 0