如何以编程方式检查视频或音频文件格式是否可以在 iPhone 中播放?
我有一些音频和视频文件存储在服务器中。我需要播放它们,但我不知道iPhone支持播放的服务器中存储的文件,
如何在开始播放之前检查IPhone是否支持该文件,我正在使用MPMoviePlayerController来播放文件。
I have some audio and video files stored in a server. I need to play them, but I do not know the files stored in server supported by iphone to play,
How can I check whether the file is supported by IPhone before start playing, I am using MPMoviePlayerController to play the files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从该文件创建一个 AVAsset,如下所示:
然后您可以检查其可播放属性:
You can create an AVAsset from the file like so:
You can then check its playable property:
在玩之前,不可能识别它们。当传递给电影播放器的文件格式不正确时,电影播放器将抛出错误。
为此,首先您必须观察通知:
MPMoviePlayerLoadStateDidChangeNotification
,如下所示:当您捕获此通知时,检查播放器的加载状态。如果它的loadState是“MPMovieLoadStateUnknown”,那么你可以说播放电影/音频时发生了一些错误。
Before playing them, its not possible to identify. Movie player will throw error when incorrect format of file is passed to it.
For that, first you have to observe for noticiation:
MPMoviePlayerLoadStateDidChangeNotification
as following:When you catch this notification, check for players load state. If its loadState is "MPMovieLoadStateUnknown", then you can say that some error occured while playing the movie/audio.