gpt4 book ai didi

ios - MPMoviePlayerViewController -- 如何消除视频加载时的黑色闪光?

转载 作者:行者123 更新时间:2023-11-29 10:33:54 25 4
gpt4 key购买 nike

我正在使用 MPMoviePlayerViewController 在我的应用程序中显示视频。有用!唯一的问题是电影播放前有黑色闪光。

如何去除黑色闪光?我看过其他线程,但它们似乎没有适用于 MPMoviePlayerViewController 的解释,并且对于像我这样的新手来说足够具体/详细(大多数是针对 MPMoviePlayerController 的)。

非常感谢任何帮助!

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"aiw_intro_video" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];

MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] init];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
mpvc.moviePlayer.controlStyle = MPMovieControlStyleNone;
[mpvc.moviePlayer setContentURL:fileURL];
[mpvc.moviePlayer play];

[self presentViewController:mpvc animated:NO completion:NULL];

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

最佳答案

在不断地迭代和调整之后,我偶然发现了一个使用 MPMoviePlayerController 的解决方案。

不要忘记在 .h 文件中声明属性,例如

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

然后

// Add default image to smooth transition
UIImage *myImage = [UIImage imageNamed:@"aiw_launch1136_black.png"];
self.videoStartFrame.image = myImage;

// Play the intro video
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"aiw_intro_video" ofType:@"mp4"]]];

self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
[self.moviePlayer.view setFrame:self.view.bounds];

[self.view addSubview:self.moviePlayer.view];

self.moviePlayer.view.hidden = YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isMovieReady:) name:MPMoviePlayerLoadStateDidChangeNotification object:self.moviePlayer];


// Detect that the video is ready and unhide the view

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

MPMoviePlayerController *moviePlayer = [notification object];

if(moviePlayer.loadState & (MPMovieLoadStatePlayable | MPMovieLoadStatePlaythroughOK))
{
self.moviePlayer.view.hidden = NO;
}
}

关于ios - MPMoviePlayerViewController -- 如何消除视频加载时的黑色闪光?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28076737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com