Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to distinguish between a live stream and an on-demand file stream with AVPlayer?

I'm trying to create a more generic media controller for several types of streaming media and want to adapt the UI to the type of stream;

  • When it's an on-demand file stream (i.e. a single MP3 file that's being streamed), you should be able to seek forward and backward. Thus, the seek slider should be visible.
  • When it's a live stream, it isn't possible to seek forward and backward, and thus the seek slider should be hidden.

Is there any way to determine from the AVPlayer (or perhaps the AVPlayerItem or AVAsset) what the type of stream is?

like image 290
SpacyRicochet Avatar asked Jan 19 '23 06:01

SpacyRicochet


1 Answers

The duration of live video is indefinite:

AVPlayer * player = ...;
const BOOL isLive = CMTIME_IS_INDEFINITE([player currentItem].duration);

You have to check the duration only when the AVPlayerItem item status is AVPlayerItemStatusReadyToPlay.

like image 107
Aleksandr Sergeev Avatar answered Jan 30 '23 02:01

Aleksandr Sergeev