1

I am using AVPlayer to run a HLS video. The video has no sound. Also i have a audio track url of same format m3u8. Can i somehow change the AVPlayer item asset or something while running my video without sound to add my other audio track so that they are sort of played together.

Nikhil Gupta
  • 881
  • 6
  • 14

1 Answers1

2

Disappointingly, you can't create an AVComposition using non local video and audio tracks and play that.

But HLS is at its heart a sort of textual playlist consisting of media pieces that can be played either serially or concurrently. If you inspect both your video and audio m3u8 streams, you should be able to concoct a new single m3u8 stream that includes both video and audio.

HOWEVER, disappointingly, it seems you can't play this resulting stream as a local file (why!?!), so you'd set up an http server to serve it to you, either locally or from or afar, or maybe (!?) you could avoid all that with a clever use of AVAssetResourceLoaderDelegate.

It also seems synchronising two AVPlayers is unsupported too, although perhaps that situation has improved.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159