2012-09-03 5 views
-1

iPhone 시뮬레이터에서 비디오를 재생하고 싶습니다. MPMoviePlayerViewController 함께 시도했지만 그 재생되지 않습니다. 아무도 그것을하는 방법에 대한 아이디어가 있습니까? 좋은 튜토리얼이 있으면 찾도록 도와주세요. 고맙습니다.iPhone 시뮬레이터에서 비디오를 재생하는 방법

참고 : MPMoviePlayerController

+1

참조를 사용하여 [이] (http://stackoverflow.com/questions/4941803/mpmovieplayercontroller-tutorial-needed). – Adam

+0

나중에 개선 할 수 있도록 아래로 투표 한 이유를 언급하십시오. – Newbee

+1

downvotes에 대한 이유는 특정 질문이 아니라는 것입니다. 또한 stackoverflow 자체에서 솔루션을 찾았다면 검색했을 수도 있습니다. 어떤 질문을하기 전에 이것을 확인하십시오. – IronManGill

답변

3

그냥 드래그 MPMoviePlayerViewController에 관한 질문 및 Xcode 프로젝트에 비디오 파일을 삭제

는 "에서는 videoURL"비디오의 URL을 지정

NSURL *url = [NSURL URLWithString:videourl]; 
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];  
[self presentMoviePlayerViewControllerAnimated:moviePlayer1]; 

그것은 실행됩니다 완벽하게 시뮬레이터

link

+0

그래도 프로젝트에 파일을 추가하지 않고도이 작업을 수행 할 수 없습니까? – Newbee

2

ARC 가정.

사용 예를 들어 당신의 viewDidLoad 방법에 그 전화하여보기로 해당 컨트롤러를 추가 할 수 있습니다

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSBundle *bundle = [NSBundle mainBundle]; 
    NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"]; 
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath]; 
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
    theMovie.scalingMode = MPMovieScalingModeAspectFill; 
    [theMovie play]; 

    [self.view addSubview:theMovie.view]; 
    [self addChildViewController:theMovie]; 
} 
2

을 내 헤더 파일에 내가 쓰기 :

MPMoviePlayerController *moviePlayer; 

이 속성 :

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer; 

및 moviePlayer를 초기화하는 방법에서 :

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl]; 
self.moviePlayer = player; 
2

다음 코드를

MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc] 
initWithContentURL:yourVideoURL]; 

moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110); 
[self.view addSubview:moviePlayer1.view]; 
[[NSNotificationCenter defaultCenter]addObserver:self 
             selector:@selector(movieFinishedCallback:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:moviePlayer1]; 
[moviePlayer1 play]; 
관련 문제