Get channels count for an audio stream in AVPlayer

In an m3u8 manifest, audio EXT-X-MEDIA tags usually contain CHANNELS tag containing the audio channels count like so:

#EXT-X-MEDIA:TYPE=AUDIO,URI="audio_clear_eng_stereo.m3u8",GROUP-ID="default-audio-group",LANGUAGE="en",NAME="stream_5",AUTOSELECT=YES,CHANNELS="2"

Is it possible to get this info from AVPlayer, AVMediaSelectionOption or some related API?

AVAudioFormat, AVAudioNode and AVPlayer itself, via audio track descriptions with CMAudioFormatDescriptionGetStreamBasicDescription all provide channel count information.

Rico


WWDR | DTS | Software Engineer

Hello @okycelt,

You can observe when the AVPlayerItem's tracks property updates:

             playerItem.publisher(for: \.tracks).sink { newTracks in
                for track in newTracks {
                    if let assetTrack = track.assetTrack, assetTrack.mediaType == .audio {
                        // Do something with the audio track.
                    }
                }
            }.store(in: &subscriptions)
Get channels count for an audio stream in AVPlayer
 
 
Q