如何以编程方式检查视频或音频文件格式是否可以在 iPhone 中播放?

发布于 2024-10-16 12:07:55 字数 128 浏览 6 评论 0原文

我有一些音频和视频文件存储在服务器中。我需要播放它们,但我不知道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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南城追梦 2024-10-23 12:07:55

您可以从该文件创建一个 AVAsset,如下所示:

NSURL *myURL = [NSURL URLWithString:@"http://www.myserver.com/myfile.mp4"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:myURL];

然后您可以检查其可播放属性:

if (asset.playable) {
    //Do Something
}

You can create an AVAsset from the file like so:

NSURL *myURL = [NSURL URLWithString:@"http://www.myserver.com/myfile.mp4"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:myURL];

You can then check its playable property:

if (asset.playable) {
    //Do Something
}
心的位置 2024-10-23 12:07:55

在玩之前,不可能识别它们。当传递给电影播放器​​的文件格式不正确时,电影播放器​​将抛出错误。
为此,首先您必须观察通知:MPMoviePlayerLoadStateDidChangeNotification,如下所示:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

当您捕获此通知时,检查播放器的加载状态。如果它的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:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文