MPMoviePlayerViewController method click on pause - iphone

I'm using MPMoviePlayerViewController and I want to know if there is a method that can tell me when the user clicks on the Pause button for the video, like an observer?

You should use MPMoviePlayerController instead :
Movie Player Notifications
The MPMoviePlayerController class generates numerous notifications to keep your application informed about the state of movie playback. In addition to being notified when playback finishes, interested clients can be notified in the following situations:
When the movie player begins playing, is paused, or begins seeking forward or backward
When the scaling mode of the movie changes
When the movie enters or exits fullscreen mode
When the load state for network-based movies changes
When meta information about the movie itself becomes available
For more information, see the Notifications section in this document.
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html

Related

Flutter Implementing pause and play..... Streaming Music

I've tried multiple flutter plug-ins to stream and play and pause music but as of currently, I haven't yet figured out a simple way to implement play and pause, whilst having the ability to avoid music overlapping, I want so that when the current song is playing, if I were to press play on new music track, the current song playing will stop and play the newly pressed song. I've tried flutter_sound, audio player, audio file player, and flute music player but I can't seem to figure out how to do this.
If it is possible either using one of these or a new plug-in, is there a way to implement what I have just described.
The library you seek is more of a multi-track player than a player. Which does not currently exists AFAIK.
The simplest way is to act according to the status of the tracks (which should be given by the player).
Roughly, what I suggest: have something that keeps the status (e.g. paused, playing, completed) of each track. (e.g. List of Tracks) When you press play on track 2 or track 1 finishes playing, you set to 'completed' (or as you wish) the track 1 and set to 'playing' the track 2.
Have a listener on the status of the current track and voila (for autoplay). When the track completes, notify the listener to call a function to start the next one on your list. When you press another track, set to 'completed' the current track and to 'playing' the track you pressed, then notify listeners.
Any library letting you know the status of a track is good enough for your purpose.

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];
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.
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.
prepareToPlay
Prepares a movie player for playback. (required) 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.
play
Initiates playback of the current item. (required) 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.
Please visit MPMediaPlayback Protocol Reference

Movie is played with some delay after calling play on MPMoviePlayerController

I am developing an iPhone application in which I play videos using MPMoviePlayerController.
Sometimes, some of the videos don't play immediately after I call play on MPMoviePlayerController.
I have called prepareToPlay and in the notified method of MPMediaPlaybackIsPreparedToPlayDidChangeNotification, I am calling play on MPMoviePlayerController.
Could someone help in identifying the problem here?
Thanks,
Laxmilal
From my answer in a similar thread (reducing-the-initial-delay-when-playing-remote-video-content) - Note this fragment of the solution is valid for both, remote and local video content.
Use theMPMoviePlayerController.movieSourceTypeproperty when initializing your
player to cut down the media
recognition delay.
From the MPMoviePlayerController Class Reference:
The default value of this property is
MPMovieSourceTypeUnknown. This
property provides a clue to the
playback system as to how it should
download and buffer the movie content.
If you know the source type of the
movie, setting the value of this
property before playback begins can
improve the load times for the movie
content. If you do not set the source
type explicitly before playback, the
movie player controller must gather
this information, which might delay
playback.

How to mute background audio while recording (using Audio Queue Services)

I have an application which uses Audio Queues to do recording of spoken user input.
This only happens for short durations and only when the user presses a button.
I'd like to allow the user's background music to continue playing, except have it muted or playing at a much lower volume whenever the recording is actually taking place (to avoid recording the audio playing out of the speaker).
For my recording queue, I'm using the PlayAndRecord category, and I have the OverrideCategoryMixWithOthers property set to true.
This problem became less of an issue in iOS4+, when they added the AudioSessionSetActiveWithFlags API and the kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation flag.
To pause background music while recording, you need to call AudioSessionSetActive(false), which will deactivate your audio session, then switch categories to PlayAndRecord mode, and set the OverrideCategoryMixWithOthers property to false.
Now, reactivate your session with AudioSessionSetActive(true) with these settings, the audio session for iPod/Pandora/etc will be interrupted and will fade-out and pause.
Then, when your recording is finished, deactivate your session again using
AudioSessionSetActiveWithFlags(false, kAudioSessionSetActiveFlag_NotifyOthersOnDeactivation);
This will notify the background music apps that their session is no longer interrupted and they can begin playing music.
Finally, you can set up your audio session again using MediaPlayback (or equiv.) mode and setting the OverrideCategoryMixWithOthers property to true again.

Keep playing sound with MPMoviePlayerController and locked screen?

When you're watching a video with MPMoviePlayerController and the user presses the top button to lock the screen, the app goes to sleep and so does the sound from the video.
Is there any way to prevent the lock from stopping the sound? If not, is there a way to intercept the lock, to create a "custom lock", to save some battery but keep playing the video?
Sounds like you haven't set your audio session category. Set the AVAudioSession's category property to AVAudioSessionCategoryPlayback to indicate that the app's major purpose is to play back audio, and it therefore should ignore the screen lock button and ring/silent switch. If you're working with the lower-level C API, you'll be using AudioSessionSetProperty(kAudioSessionCategory_MediaPlayback), but it's the same concept.