我正在实现AVPlayer(不是AVAudioPlayer)并试图从URL播放音频。它工作正常。但正如我们所知,有时我们可能会有无效的URL(没有音频字节的URL)。 当我从任何网址播放音频时,AVPlayer状态始终显示AVPlayerStatusReadyToPlay ,这是错误的。例如:在网址部分中,如果提供无效网址,例如: http://soundx.mp3slash.net/indian/jhankar_beats/1%28mp3pk.com%29.mp3(即使在您的浏览器中也不起作用),即使您提供 https://stackoverflow.com/questions/ask 或任何站点URL(没有音频字节),AVPlayer始终显示AVPlayerStatusReadyToPlay。 我认为在这种情况下它的状态必须是AVPlayerItemStatusUnknown或AVPlayerStatusFailed 请大家帮忙,如何知道URL无效(AVPlayerItemStatusUnknown或AVPlayerStatusFailed)显示我可以向用户显示消息。 提前致谢
Only public methods of the bean class (and any superclasses) may be invoked through the no-interface
view. Attempted invocations of methods with any other access modifiers via the no-interface view reference
must result in the javax.ejb.EJBException.
When interacting with a reference to the no-interface view, the client must not make any assumptions
regarding the internal implementation of the reference, such as any instance-specific state that may be
present in the reference. Although the reference object is type-compatible with the corresponding bean
class type, there is no prescribed relationship between the internal implementation of the reference and
the implementation of the bean instance.
{
-(void)playButtonClicked
}
NSURL *url = [NSURL URLWithString:AUDIO_URL];
[self.audioSliderBar setMinimumValue:AUDIO_SLIDER_BAR_0];
playerItem = [AVPlayerItem playerItemWithURL:url];
player = [AVPlayer playerWithPlayerItem:playerItem];
player.volume=5.0;
[player addObserver:self forKeyPath:STATUS options:0 context:nil];
[playerItem addObserver:self forKeyPath:PLAY_BACK_BUFFER_EMPTY options:NSKeyValueObservingOptionNew context:nil];
[playerItem addObserver:self forKeyPath:PLAY_BACK_LIKELY_TO_KEEP_UP options:NSKeyValueObservingOptionNew context:nil];
addObserverFlag=YES;
答案 0 :(得分:3)
状态属性的可能值,用于指示是否可以成功播放项。
AVPlayerStatusReadyToPlay 表示播放器已准备好播放 AVPlayerItem实例。
所以我认为您需要通过AVPlayerItemStatus
类型的状态属性检查特定项目的状态