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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3150383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:29:49  来源:igfitidea点击:

How to use MPMoviePlayerViewController on iOS4(3.1.3 update)

iphonexcodeios4

提问by SUKIYAKI

My iPhone is a iOS4(3.1.3 update). I tryid this code.

我的 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

when I run the aplication the video didn't work just only plays sound. What is wrong with this code?

当我运行应用程序时,视频不起作用,只是播放声音。这段代码有什么问题?

Thanks.

谢谢。

回答by chandu

just add below source to code:-

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

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

[self.view addSubview:themovie.view];

Then it will worked sure......

那么它肯定会起作用......