How to check if AVPlayer has Video or just Audio?

后端 未结 4 1792
一向
一向 2021-01-12 09:48

I try to play some \"media\" but at the time the AVPlayer starts I don\'t know if it is audio or Video.

I connected the player Layer and it works fine.



        
4条回答
  •  没有蜡笔的小新
    2021-01-12 10:21

    This helped me:

        // source from https://stackoverflow.com/a/55581216 Changed for last release AVFoundation
        func isAudioAvailable() -> Bool? {
            return self.player.currentItem?.tracks.filter({$0.assetTrack!.mediaType == AVMediaType.video}).count != 0
        }
        
        func isVideoAvailable() -> Bool? {
            return self.player.currentItem?.tracks.filter({$0.assetTrack!.mediaType == AVMediaType.video}).count != 0
        }
    

提交回复
热议问题