gpt4 book ai didi

iPhone - 在 3.0 和 4.0 操作系统/SDK 上播放视频?

转载 作者:行者123 更新时间:2023-11-28 21:40:54 25 4
gpt4 key购买 nike

从3.2 iPhone OS SDK开始,播放视频真的不一样了。

所以我想知道是否有一种方法可以在不为这两种情况编写代码的情况下使用兼容代码(< 和 >3.2)全屏播放视频。

我认为我们必须编写两个版本的类来处理视频播放...

你的!

最佳答案

我基本上按照 Jeff Kelly 上面的建议在 3.1 及更高版本上运行,注意 instanceRespondToSelector 调用:

// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];


//Will only run this code for >= OS 3.2
if ([MPMoviePlayerController instancesRespondToSelector:@selector(setFullscreen:animated:)]){

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(nowPlayingMovieDidChange:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];

mp.controlStyle = MPMovieControlStyleFullscreen;


[mp setScalingMode:MPMovieScalingModeAspectFit];

//change mainMenu here to whatever your parent view is
[mp.view setFrame:mainMenu.frame];
[self.view addSubview:mp.view];



[mp setFullscreen:YES animated:NO];
}
//continue as normal

然后在 moviePlayBackDidFinish 函数中,我使用相同的技术来删除通知。

关于iPhone - 在 3.0 和 4.0 操作系统/SDK 上播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2681850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com