gpt4 book ai didi

iphone - 将 MBProgressHud 添加到 MPMoviePlayerController

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:03:29 24 4
gpt4 key购买 nike

我正在尝试向 MPMoviePlayerController 显示 MBProgressHud,因为我正在观察 MPMoviePlayer 的加载状态通知,但不知何故方法观察通知除了 MPMovieLoadStatePlayable 之外,从不观察加载状态的通知。我在视频开始流式传输时显示 MBProgressHud 但在播放后它不起作用然后暂停下载视频,因此我无法在视频加载时吸引用户,如果有人有更好的方法请提及它,或者如果以下代码有任何问题,请告诉我。

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

MPMoviePlayerController *player = [notification object];


if ((player.loadState & MPMovieLoadStatePlayable) == MPMovieLoadStatePlayable) {
NSLog(@"Load state Playable");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];

}else if ((player.loadState & MPMovieLoadStatePlaythroughOK) == MPMovieLoadStatePlaythroughOK){
NSLog(@"Load state Playing");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}else if ((player.loadState & MPMovieLoadStateStalled) == MPMovieLoadStateStalled){
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSLog(@"Load state stalled");
}else if ((player.loadState & MPMovieLoadStateUnknown) == MPMovieLoadStateUnknown){
NSLog(@"Load State unknown");

}

}

最佳答案

好的 .. 我遇到了你的问题,问题是你没有收到除 MPMovieLoadStatePlayable 之外的加载状态通知。所以在这里你可以做的是......就像下面......

在viewdidload下面写下通知

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

在 ViewDidLoad 中定义它之后,实现如下所示的那些功能....

 - (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
{
//your code....
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
NSString *reason = @"Unknown";
switch (finishReason)
{
case MPMovieFinishReasonPlaybackEnded:
reason = @"Playback Ended";
break;
case MPMovieFinishReasonPlaybackError:
reason = @"Playback Error";
break;
case MPMovieFinishReasonUserExited:
reason = @"User Exited";
break;
}
NSLog(@"Finish Reason: %@%@", reason, error ? [@"\n" stringByAppendingString:[error description]] : @"");
}


- (void) moviePlayerPlaybackStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = notification.object;
NSString *playbackState = @"Unknown";
switch (moviePlayerController.playbackState)
{
case MPMoviePlaybackStateStopped:
playbackState = @"Stopped";
break;
case MPMoviePlaybackStatePlaying:
playbackState = @"Playing";
break;
case MPMoviePlaybackStatePaused:
playbackState = @"Paused";
break;
case MPMoviePlaybackStateInterrupted:
playbackState = @"Interrupted";
break;
case MPMoviePlaybackStateSeekingForward:
playbackState = @"Seeking Forward";
break;
case MPMoviePlaybackStateSeekingBackward:
playbackState = @"Seeking Backward";
break;
}
NSLog(@"Playback State: %@", playbackState);
}


- (void) moviePlayerLoadStateDidChange:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = notification.object;
NSMutableString *loadState = [NSMutableString new];
MPMovieLoadState state = moviePlayerController.loadState;
if (state & MPMovieLoadStatePlayable)
[loadState appendString:@" | Playable"];
if (state & MPMovieLoadStatePlaythroughOK)
[loadState appendString:@" | Playthrough OK"];
if (state & MPMovieLoadStateStalled)
[loadState appendString:@" | Stalled"];

NSLog(@"Load State: %@", loadState.length > 0 ? [loadState substringFromIndex:3] : @"N/A");
}

让我知道它是否有效!!!

快乐编码!!!!

关于iphone - 将 MBProgressHud 添加到 MPMoviePlayerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18051318/

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