Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between prepareToPlay and Play in MPMoviePlayerController

Please let me know the difference between prepareToPlay & play Methods in MPMoviePlayerController at the time of Video Play.

The syntax are:

[moviePlayer prepareToPlay];

And

[moviePlayer play];
like image 909
Myaaoonn Avatar asked Jan 17 '26 18:01

Myaaoonn


2 Answers

As Method say that

prepareToPlay - is not starting to play but it is under process for play whatever (video/audio).

play - says that it is do string to play whatever (video/audio).

as Document say:

play

Initiates playback of the current item. (required)

- (void)play  

Discussion
If playback was previously paused, this method resumes playback where it left off; otherwise, this method plays the first available item, from the beginning.

If a movie player is not prepared for playback when you call this method, this method first prepares the movie player and then starts playback. To minimize playback delay, call the prepareToPlay method before you call this method.

To be notified when a movie player is ready to play, register for the MPMoviePlayerLoadStateDidChangeNotification notification. You can then check load state by accessing the movie player’s loadState property.

Availability Available in iOS 3.2 and later. Declared In MPMediaPlayback.h

prepareToPlay

Prepares a movie player for playback. (required)

- (void)prepareToPlay

Discussion
If a movie player is not already prepared to play when you call the play method, that method automatically calls this method. However, to minimize playback delay, call this method before you call play.

Calling this method may interrupt the movie player’s audio session. For information on interruptions and how to resond to them, see Audio Session Programming Guide.

Availability Available in iOS 3.2 and later.

Declared In MPMediaPlayback.h

For More Information read This Official Documentation.

like image 195
iPatel Avatar answered Jan 20 '26 07:01

iPatel


To minimise playback latency by performing expensive operations upfront.

In order to play back a multimedia file, such as a QuickTime movie, there is a non-trivial amount of loading and processing required before the file can actually be played. Having separate play and prepareToPlay methods allows the developer to choose when potentially expensive operations involved with playback can be performed, to minimise the delay when the user actually presses the play button.

For example, the header needs to be read and parsed, and metadata extracted. The chapter index might need to be read, and the player might need to seek to the end of the file to read chunk offset tables, read thumbnails, poster frames and and many more. Also, to enable rapid playback when the user presses play, the system probably wants to load, uncompress and cache the first second or so of audio and video content. All of this can take a noticeable amount of time, and would be performed by the prepareToPlayback method.

Given the above, the play method can immediately start to play the multimedia content when the user nominates. Obviously, if the media hasn't already been prepared, the system would call prepareForPlayback for you at the start of play to perform these necessary preparations.

In your app, for example, the user might select a multimedia clip in one step. You could call prepareToPlay right away, and show the poster frame in the preview window. Then when the user presses the Play> button, the content is ready to go.

A simplistic parallel in the analog world might be something akin to threading the tape into a spool, winding up the spool and pretensioning the tape, positioning the tape head at the start of the content. Then when you press Play, the sound is heard almost immediately.

like image 25
gavinb Avatar answered Jan 20 '26 06:01

gavinb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!