如何在iOS4上使用MPMoviePlayerViewController(3.1.3更新)

时间:2010-06-30 14:48:56

标签: iphone xcode ios4

我的iPhone是iOS4(3.1.3更新)。 我试过这段代码。


#import <UIKit/UIKit.h>

@interface testViewController : UIViewController {
}

@end
//-------------------------------------------------
#import <MediaPlayer/MediaPlayer.h>
#import "testViewController.h"

@implementation testViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  NSBundle *Bundle = [NSBundle mainBundle];
  NSString *moviePath = [Bundle pathForResource:@"test" ofType:@"MOV"];
  NSURL *videoURL = [[NSURL fileURLWithPath:moviePath] retain];

  MPMoviePlayerViewController *theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]; 
  [self presentMoviePlayerViewControllerAnimated:theMovie];
  theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
  [theMovie.moviePlayer play];
}

- (void)dealloc {
    [super dealloc];
}

@end

当我运行应用程序时,视频无法正常播放声音。 这段代码有什么问题?

感谢。

1 个答案:

答案 0 :(得分:2)

只需将以下源代码添加到代码中: -

[themovie.view setFrame: self.view.bounds];  

[self.view addSubview:themovie.view];

然后它会确定......