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.
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
}
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.
精彩评论