Iphone 基于iOS4和部署iOS3的媒体播放器存在问题
在设备3.1.2上运行时,为什么还要传递if(NSClassFromString(@“MPMoviePlayerServiceWController”)!=nil 而iOS4的代码会崩溃吗,如何解决这个问题Iphone 基于iOS4和部署iOS3的媒体播放器存在问题,iphone,media-player,ios4,Iphone,Media Player,Ios4,在设备3.1.2上运行时,为什么还要传递if(NSClassFromString(@“MPMoviePlayerServiceWController”)!=nil 而iOS4的代码会崩溃吗,如何解决这个问题 if(NSClassFromString(@"MPMoviePlayerViewController") != nil) { // iOS 4 code NSLog(@"MPMovi
if(NSClassFromString(@"MPMoviePlayerViewController") != nil) {
// iOS 4 code
NSLog(@"MPMoviePlayerViewController");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:AppDelegate.PushLink]];
if (mp) {
// save the movie player object
self.theMovie4 = mp;
[mp release];
//Present
[self presentMoviePlayerViewControllerAnimated:self.theMovie4];
// Play the movie!
self.theMovie4.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self.theMovie4.moviePlayer play];
}
}
else {
//iOS 3 Code
AppDelegate = nil;
AppDelegate = [[UIApplication sharedApplication] delegate];
[AppDelegate ForceHideNavigationBar];
theMovie3 = nil;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:theMovie3];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie3];
// Register to receive a notification when the movie scaling mode has changed.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieScalingModeDidChange:)
name:MPMoviePlayerScalingModeDidChangeNotification
object:theMovie3];
theMovie3 = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:AppDelegate.PushLink]];
[theMovie3 play];
}
我在我的应用程序上做了一件非常类似的事情,它使用4.0作为基本SDK,但我也瞄准了iOS3设备。我必须检查操作系统版本,以便为视频播放提供正确的代码。例如:
- (void) playMovieAtURL: (NSURL*) theURL {
NSLog(@"playMovieAtURL");
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
NSLog(@"> 3.2");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
if (mp)
{
// save the movie player object
//self.moviePlayerViewController = mp;
//[mp release];
[self presentMoviePlayerViewControllerAnimated:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[mp.moviePlayer play];
[mp release];
}
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
NSLog(@"< 3.2");
MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL: theURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
// 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];
}
}
-(无效)播放电影自然:(NSURL*)URL{
NSLog(“Playmovieatural”);
如果([[[UIDevice currentDevice]systemVersion]doubleValue]>=3.2){
NSLog(@“>3.2”);
mpmovieplayervewcontroller*mp=[[mpmovieplayervewcontroller alloc]initWithContentURL:theURL];
if(mp)
{
//保存电影播放器对象
//self.movieplayervewcontroller=mp;
//[mp发布];
[自我呈现的电影播放服务控制器:mp];
mp.moviePlayer.movieSourceType=mpmoviesourcetype文件;
[mp.moviePlayer play];
[mp发布];
}
}
如果([[[UIDevice currentDevice]systemVersion]doubleValue]<3.2),则为else{
NSLog(@“<3.2”);
MPMoviePlayerController*theMovie=[[MPMoviePlayerController alloc]initWithContentURL:theURL];
movie.scalingMode=MPMovieScalingModeAspectFill;
//注册播放完成通知
[[NSNotificationCenter defaultCenter]
addObserver:self
选择器:@selector(myMovieFinishedCallback:)
名称:MPMoviePlayerPlaybackDidFinishNotification
对象:theMovie];
//电影播放是异步的,因此此方法立即返回。
[电影剧];
}
}
希望这有帮助
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
NSString *movpath = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
MPMoviePlayerViewController* mpviewController = [[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:movpath]];
[window addSubview:mpviewController.view];
[window makeKeyAndVisible];
MPMoviePlayerController *mp = [mpviewController moviePlayer];
[mp prepareToPlay];
[[mpviewController moviePlayer] play];
此代码将在iOS4中工作
但是,它会在电影完成后退出,因为您必须为通知创建方法。您还需要在那里发布电影,以便捕获内存泄漏。这是一个巨大的帮助。谢谢你,斯蒂兹!谢谢!它救了我一天!