2013-09-18 2 views
0

Я пытаюсь заменить AVPlayer на MPMoviePlayerController, так как хочу добавить анимацию с прозрачным фоном в представление. Проблема заключается в том, что анимация не отображается с помощью MPMoviePlayerController.Замена AVPlayer с помощью MPMoviePlayerController

Пожалуйста, найдите мои строки ниже. Первая часть - с AVPlayer, и это работа. Второй - с MPMoviePlayerController, и нет.

Что делает код, он воспроизводит анимацию, и когда это делается, оно запускает действие.

код с AVPlayer (который работает):

NSString *filepath = [[NSBundle mainBundle] pathForResource:theAnimationFileName ofType:theString; 

//NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
// First create an AVPlayerItem 

AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:fileURL]; 

// Subscribe to the AVPlayerItem's DidPlayToEndTime notification. 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem]; 

// Pass the AVPlayerItem to a new player 
controlledPlayer = [[AVPlayer alloc] initWithPlayerItem:playerItem]; 

AVPlayerLayer *animatedLayer = [AVPlayerLayer playerLayerWithPlayer:controlledPlayer]; 


[animatedLayer setFrame:CGRectMake(0, 0, 1024, 1024)]; 
[thisReplacementView.layer addSublayer: animatedLayer]; 


// Begin playback 
[controlledPlayer play]; 

код с MPMoviePlayerController (ничего не отображается):

NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:theString]; 

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]]; 

moviePlayer.controlStyle = MPMovieControlModeDefault; 

moviePlayer.view.frame = CGRectMake(0, 0, 1024, 1024); 

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


[thisReplacementView addSubview:moviePlayer.view]; 

[moviePlayer play]; 

ответ

0
NSURL *url = [NSURL URLWithString:@"http://iOS.mp4"]; 
self.moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
NSError *_error = nil; 
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &_error]; 
[self presentMoviePlayerViewControllerAnimated:self.moviePlayer]; 

-(void)playbackFinishedCallback:(NSNotification *)notification{ 

    self.moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:self.moviePlayer]; 
} 
- (void)moviePlaybackComplete:(NSNotification *)notification 
{ 
    self.moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:self.moviePlayer]; 
    [self.moviePlayer.view removeFromSuperview]; 
} 
Смежные вопросы