问题
I am trying to create a simple app for the iPad that with play an FLV when you click a button. I am using the code from http://developer.apple.com/iphone/library/codinghowtos/AudioAndVideo/index.html#VIDEO-USE_THE_MEDIA_PLAYER_FRAMEWORK_FOR_VIDEO_PLAYBACK as a reference. Here is the code for my click event
-(IBAction) btnPlayVideoClick:(id) sender {
NSString* videoPath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"flv"];
MPMoviePlayerController* myMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:videoPath]];
myMovie.scalingMode = MPMovieScalingModeAspectFill;
// Register for the playback finished notification.
[[NSNotificationCenter defaultCenter] addObserver:self
selector: @selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:myMovie];
[myMovie play];
}
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];
// Release the movie instance created in playMovieAtURL
[theMovie release];
}
I am able to successfully compile and run the app, but when I click the button the app just exits with no error message or any activity at all. Is there something that I am doing wrong, or is there some reason I cannot play an FLV using the simulator. I can't test on a real device yet because I am waiting for approval to get my dev license.
Thanks,
Mike
回答1:
iOS devices do not have Flash, so you can't play any Flash video.
回答2:
iOS doesn't have the correct codecs to play an FLV. It needs to be reencoded as a .mp4 or .mov file. Something that iOS can actually play. I haven't tried to read your code to see if it's valid.. this is just the first thing I notice as being "incorrect".
回答3:
Seeing that you already addressed the Flash issue the next issue I see is that you don't seem to be putting the player view anywhere. You either need to put the view somewhere in your hierarchy or set myPlayer.fullscreen = TRUE; Without knowing more about your views I can't give you advice on embedding it but check out this bit of sample code from Apple to see how they do it: http://developer.apple.com/iphone/library/documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html#//apple_ref/doc/uid/TP40006953-CH3-DontLinkElementID_1
来源:https://stackoverflow.com/questions/3345601/can-i-play-an-flv-on-the-ipad-simulator