ios - MPMoviePlayerController 错误的 URL 错误
<p><p>如果我给 MPMoviePlayerViewController 一个错误的视频 URL 来播放,像这样:</p>
<pre><code>[ initWithContentURL:];
</code></pre>
<p>有没有办法通知视频没有下载?</p>
<p>我尝试了以下两种方法,但在任何一种情况下都没有收到通知:</p>
<pre><code>[ addObserver:self selector:@selector(loadStateChanged) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[ addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>首先使用 <code>Rechability</code> 检查 URL 是否可访问。 </p>
<pre><code> NSURL *myURL = ;
NSMutableURLRequest *request = ;
;
dispatch_async( dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_BACKGROUND, NULL), ^{
NSURLResponse *response;
NSError *error;
NSData *myData = ;
BOOL reachable;
if (myData) {
// we are probably reachable, check the response
reachable=YES;
} else {
// we are probably not reachable, check the error:
reachable=NO;
}
// now call ourselves back on the main thread
dispatch_async( dispatch_get_main_queue(), ^{
;
});
});
</code></pre>
<p>它提到的是这个答案<a href="https://stackoverflow.com/a/9617166/1721884" rel="noreferrer noopener nofollow">link</a> </p>
<p>或</p>
<pre><code>[ addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
- (void) playbackDidFinish:(NSNotification*)notification{
NSNumber* reason = [ objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch () {
case MPMovieFinishReasonPlaybackEnded:
NSLog(@"Playback Ended");
break;
case MPMovieFinishReasonPlaybackError:
NSLog(@"Playback Error"); //// this include Bad URL
break;
case MPMovieFinishReasonUserExited:
NSLog(@"User Exited");
break;
default:
break;
}
}
</code></pre>
<p>或者添加一个自定义函数来检查请求超时..</p>
<pre><code>;
</code></pre>
<p>如果您的代码中没有收到任何 <code>通知</code> <br/>
请检查此答案以供进一步引用。 <a href="https://stackoverflow.com/a/26190790/1721884" rel="noreferrer noopener nofollow">link</a> </p></p>
<p style="font-size: 20px;">关于ios - MPMoviePlayerController 错误的 URL 错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26184103/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26184103/
</a>
</p>
页:
[1]