我建議使用指定的播放器流式傳輸這些文件。如果您使用WebView播放這些文件,您可以先將它們加載到播放器中進行狀態檢查。這裏有一個MPMoviePlayerController
例如在如何做到這一點:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:audioUrl];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification
object:player];
if ([player respondsToSelector:@selector(loadState)])
{
...
}
檢查loadState
會告訴你流的狀態:
enum {
MPMovieLoadStateUnknown = 0,
MPMovieLoadStatePlayable = 1 << 0,
MPMovieLoadStatePlaythroughOK = 1 << 1,
MPMovieLoadStateStalled = 1 << 2,
};
因爲MPMoviePlayerController
是在iOS 9不贊成我建議以搜索對於最近的iOS版本,使用AVPlayerViewController
以上。
只是一個想法...怎麼樣使用nsurlconnection開始流式傳輸,並檢查您是否收到數據? –
你可以先嚐試canOpenUrl。 –