2011-08-31 44 views
8

Tôi có một lớp con MPMoviePlayerController sẽ hiển thị các điều khiển khi phát lại xong. Tôi đã đính kèm một phản hồi cho thông báo MPMoviePlayerPlaybackDidFinishNotification và đã thử đặt kiểu điều khiển như sau:Hiển thị các điều khiển theo chương trình trong MPMoviePlayerController

[self setControlStyle:MPMovieControlStyleEmbedded]; 

Điều này không hoạt động. Về bản chất, ở cuối video tôi muốn kiểm soát để hiển thị. Làm cách nào để hiển thị các điều khiển theo chương trình?

GHI CHÚ: Bộ điều khiển KHÔNG ở chế độ toàn màn hình.

+0

Bạn có chắc chắn rằng MPMoviePlayerPlaybackDidFinishNotification đang được thông báo không? Bạn có thể đặt điểm ngắt hoặc thông báo NSLog ở đó để đảm bảo. –

+0

Bạn đã bao giờ tìm ra một giải pháp cho Robert này? – ToddH

+0

Tôi sợ quá lâu rồi nên nhớ, nhưng tôi nghĩ cuối cùng chúng tôi đã thay đổi để sử dụng một cầu thủ khác? –

Trả lời

0

Vui lòng tìm Mã đầy đủ của tôi về vấn đề này, nó làm việc với tôi

thêm .h lớp thêm này

@property(strong,nonatomic) MPMoviePlayerViewController * moviePlayer; 

tại lớp .m thêm mã này "vượt qua URL phim"

-(void) playMovie:(NSString *)filePath 
{ 
    NSURL *theOutputURL = [NSURL fileURLWithPath:filePath]; 
    if(_moviePlayer) 
     [_moviePlayer.moviePlayer setContentURL:theOutputURL]; 
    else 
     _moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:theOutputURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(myMovieFinishedCallback:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:_moviePlayer.moviePlayer]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:_moviePlayer.moviePlayer]; 

    if (![_moviePlayer.moviePlayer isPreparedToPlay]) 
     [_moviePlayer.moviePlayer prepareToPlay]; 

    _moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
    [_moviePlayer.moviePlayer setFullscreen:YES]; 
    _moviePlayer.moviePlayer.controlStyle=MPMovieControlStyleEmbedded; 
    [_moviePlayer.moviePlayer setContentURL:theOutputURL]; 
    _moviePlayer.view.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height); 
    [_moviePlayer shouldAutorotateToInterfaceOrientation: AVCaptureVideoOrientationLandscapeRight]; 
    [self.view addSubview:_moviePlayer.view]; 
} 


- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification { 
    if (_moviePlayer.moviePlayer.playbackState == MPMoviePlaybackStateStopped) { 
     [_moviePlayer.moviePlayer setContentURL:[_moviePlayer.moviePlayer contentURL]]; 
     [_moviePlayer.moviePlayer play]; 
    } 
} 

-(void)myMovieFinishedCallback:(NSNotification*)aNotification 
{ 
    // to add your code after playback is finished 

} 
Các vấn đề liên quan