iphone - 基于iOS 4并部署iOS 3的媒体播放器问题

标签 iphone media-player ios4

当在设备3.1.2上运行时,为什么它也传递 if(NSClassFromString(@"MPMoviePlayerViewController") != nil) 做iOS4的代码就会崩溃,如何解决这个问题?

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



        }

    }

希望这有帮助!!

关于iphone - 基于iOS 4并部署iOS 3的媒体播放器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3092117/

相关文章:

android - 单击 TextView 从原始资源播放 mp3 文件

iphone - 未在文档目录文件夹中获取图像

objective-c - UITableViewCell accessoryType位置随单元格高度变化

iphone - 如何格式化 root.plist 中的字符串?

iphone - 防止备份到 iCloud,以下代码是否正确?

iphone - (iOS 4.x) 应用程序退出时清除 NSUserDefaults

ios4 - 如何在MKMapView上捕获轻击手势

iphone - 让我的网站在手机上默认缩小

安卓媒体播放器问题

尝试播放某些流时,Android MediaPlayer 返回错误 (1, -1004)