开发者

MPMoviePlayerController: Removing ±1sec black screen, when changing contentURL?

开发者 https://www.devze.com 2023-01-28 16:55 出处:网络
I\'m working on an iPad project where i have to play short video files one after another smoothly. For playing the videos i\'m using MPMoviePlayerController. The problem i\'m facing is that when i cal

I'm working on an iPad project where i have to play short video files one after another smoothly. For playing the videos i'm using MPMoviePlayerController. The problem i'm facing is that when i call

[self.moviePlayer setContentURL:videoURL]

it does start the next video, but there is ±1 sec delay of black screen before it starts to play the next video (the videos are read from the disk, not streamed). I need to avoid this black screen as well as the delay.

So maybe some of you also experienced this problem and have some solutions? Thanks.

Btw, for开发者_JAVA百科 now, as to at least avoid the black screen, I capture the last frame of the ending video, show it in a UIImageView, and remove it after 1 sec delay. But i'm hoping to find a more elegant fix.


The effect you are talking about is actually a combination of two problems: a black blink when you change the video (which doesn't happen upon assigning the video for the first time) and the delay before the controller starts playing video.

I'm currently screwed with the second one and don't know how to solve yet. As for the first one, just try to use another instance of MPMoviePlayerController. I mean when a video finishes playing (you can subscribe to a corresponding notification) just remove the old player, create a new one and put video there. This way you will avoid blinking, but there will be a delay (not sure, because of loading the video or because of player creation) before the next video starts playing.

Hope this helps a bit.


Fond solution here http://joris.kluivers.nl/blog/2010/01/04/mpmovieplayercontroller-handle-with-care/ you need to use [self.moviePlayer prepareToPlay]; and catch MPMoviePlayerReadyForDisplayDidChangeNotification to use [self.moviePlayer play];


Old post but Googlers will still come. :)

Creating a new MPMoviePlayerController then assigning it back to my previous player worked for me, no more black screen!

    ...
    [self playVideoWithFilename:@"video1.mp4"];
}

- (void)playVideoWithFilename:(NSString *)fileName
{
    MPMoviePlayerController *player = [MPMoviePlayerController new];
    _myVidPlayer = player;
    player = nil;

    NSURL *vidPath = [[NSBundle mainBundle] URLForResource:fileName withExtension:nil];

    [_myVidPlayer.view setBackgroundColor:[UIColor whiteColor]];
    [_myVidPlayer.view setFrame:CGRectMake(0, 64, 320, 320)];
    [_myVidPlayer setContentURL:vidPath];
    [_myVidPlayer setControlStyle:MPMovieControlStyleNone];
    [_myVidPlayer setRepeatMode:MPMovieRepeatModeOne];
    [_myVidPlayer prepareToPlay];
    [self.view addSubview: _myVidPlayer.view];
    [_myVidPlayer play];
}

Note:

Available in iOS 2.0 and later Deprecated in iOS 9.0

"Use AVPlayerViewController in AVKit."


I think that the problem is that the controller will fade out and back in between the movies. You can control the background view color and contents, but I'm not sure that you can eliminate the fade in/out.

0

精彩评论

暂无评论...
验证码 换一张
取 消