Check if video has audio or not

2019-08-05 17:04发布

问题:

I have to make decision if a video file (streaming from server) has audio or not. If it has audio then I have to stop already playing audio file and start video else play video with already running audio. I have managed to pause audio before playing video but how can I check audio in a video?

I am using AVAudioPlayer to play audio and MPMoviePlayerViewController to play video.

I have searched a lot on google but no success. Any help will be appreciated.

回答1:

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html#//apple_ref/doc/c_ref/MPMoviePlayerController

If you navigate to the notifications section, you will see that there is a notification:

MPMovieMediaTypesAvailableNotification

And here are the masks for given notification:

MPMovieMediaTypeMask  
enum {
   MPMovieMediaTypeMaskNone  = 0,
   MPMovieMediaTypeMaskVideo = 1 << 0,
   MPMovieMediaTypeMaskAudio = 1 << 1
};
typedef NSInteger MPMovieMediaTypeMask;