AVPLayer switch to Audio only playlist

Hello! I am using AVPLayer for play HLS-stream videos.

But I want to switch player to audio only representation of video. For that purpose we have separate playlist in master manifest:
.....
#EXT-X-STREAM-INF: Video playlists
........
#EXT-X-STREAM-INF:BANDWIDTH=123456, CODECS="mp4a.40.2", AUDIO="AACL"
index.m3u8/blablabla

.....

Is there any possibility to switch AVPLayer to play this audio manifest?

PS: I have tried to set frame of PlayerView to 0x0 but it is not switch to audio only playlist and also disabling tracks not working because it is not file-based playing.
Have you tried -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:]?
@Media Engineer

Thank you for your answer.

<<Have you tried -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:]?

I have tried but unfortunately it also doesn't work for me. I see no changes after applying media option: video is continue playing. (video chunks still downloads) The main goal to "say" player to download only audio segments because we have audio only playlist

//.visual doesn't exist
 playerView.item?.select(nil, in: asset!.mediaSelectionGroup(forMediaCharacteristic: .legible)!)
 playerView.item?.select(audible?.first, in: asset!.mediaSelectionGroup(forMediaCharacteristic: .audible)!)

po playerView.item?.currentMediaSelection

Optional(<AVMediaSelection: 0x60000206cc40, group characteristics and selected options = { AVMediaCharacteristicAudible : <AVMediaSelectionKeyValueOption: 0x6000037ccf80, language = eng, mediaType = 'soun', title = eng> }>)



To summarize my question:

I have the same structure of manifest as in that example https://developer.apple.com/documentation/http_live_streaming/example_playlists_for_http_live_streaming/creating_a_master_playlist:

#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/low/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/lo_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/hi_mid/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2"
http://example.com/high/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5"
http://example.com/audio/index.m3u8


And case the next: I play the video with audio (by AVPlayer)-> tap button “Audio mode” and want to switch to “Only audio mode” and play only http://example.com/audio/index.m3u8. without downloading video chunks. Also vice versa(switch from audio only to audio with video). Is It possible?


What I have tried:
  1. Select media option selectMediaOption as described in developer.apple.com/documentation/avfoundation/mediaplaybackandselection/selectingsubtitlesandalternativeaudiotracks

  2. Remove player from view as described in developer.apple.com/documentation/avfoundation/mediaplaybackandselection/creatingabasicvideoplayeriosandtvos/playingaudiofromavideoassetinthebackground

  3. Set player view frame to 0x0

  4. All above options together

And the result in all cases the same: Audio is playing but I see(by Charles proxy) that AVPLayer also download video chunks. Is it possible to avoid downloading video chunks and save user traffic?

Did anyone find any solution?

AVPLayer switch to Audio only playlist
 
 
Q