iPad SDK: How to play a series of videos with MPMoviePlayerViewController - ipad

I am wondering how to most efficiently play a series of video with MPMoviePlayerViewController?
For example, I would like to play in a series the following:
Video1.mp4
Video2.mp4
Video3.mp4
and so on...
Any suggestions appreciated.

Use NSNotificationCenter to monitor for the MPMoviePlayerPlaybackDidFinishNotification notification. Then, set up the player with the next item you wish to play.

You can register for the notification MPMoviePlayerPlaybackDidFinishNotification with [NSNotificationCenter defaultCenter]. Once you receive that notification, just load the next video and start playback.
Have a look at the respective class documentations for additional details.

Related

Detect end of playback on lock screen - AVPlayer

I've the array of audio file and would like to play them consecutively. Is there any way to detect when AVPlayer ending playing on lock screen so that I could call a completion handler and play next sound? I want to call nextPlayAudio() from my PlayerViewController class. I am fire notification after finishing current playback audio but nextPlayAudio() not get called after finishing.
Use the AVPlayerItemDidPlayToEndTime notification to manage this.
Example as a service here: https://github.com/noreasonprojects/ModernAVPlayer/blob/develop/Sources/Core/Services/PlaybackObservingService.swift
| Check the PlayingState file, where the service is used.

notification when AVPlayerItem is not stalled

There is a notification for when the player has stalled, called AVPlayerItemPlaybackStalled, but there doesn't seem to be one for when the video is playing again. What's a good way to know that the video has unstalled? I could look for when the player current time changes but that sounds not great...

Can we play sounds in the background at a particular intervals in the iPhone app?

In my app I need to play some sounds like beeps at a particular intervals of time (May not be uniform intervals), even the app is in the background. I have gone through the google and many suggested to use AV Foundation’s AVPlayer. I have gone through the following tutorial also.
http://www.raywenderlich.com/29948/backgrounding-for-ios
This tutorial explains how to play a queue of items.
But in my app there will not be any continuous music. Just we need to play some sounds while the app in foreground or background.
Simply i need to play sounds as RunKeeper does.
Please help me out.
You can try scheduling a local notification and providing a custom sound: https://developer.apple.com/library/ios/documentation/iphone/Reference/UILocalNotification_Class/Reference/Reference.html. This will also display an alert in notification centre / lock screen though.

iOS: play sound for duration in background

I wondering if there was a way to play a sound or music for a predetermined duration even if the app is put into the background.
For instance, say the sound is 30 mins long but only want to play it for 10 mins, how can I pause the sound while in the background. Or is there a way to tell AVAudioPlayer to loop 0.333 times?
Is there a better class to use instead of AVAudioPlayer to achieve this?
EDIT:
So far I've searched SO and Google to no avail. And have been reading through Apple's docs.
Thanks in advance for the help.
Two solutions:-
-1. You can have Local and Push Notification
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1
Notification can play sound when delivered.
-2. You can make you app run in background and play sound
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
iOS/iTunes rules limit what you can do in background to pass moderation but it mentions playing music.

Do not resume MPMoviePlayerController when application enters foreground

I am developing an iPhone application which plays the video using MPMoviePlayerController. When I switch to background(device with multi-tasking support), the video play is paused and when I bring my app to foreground video play is resumed.
But, when I switch to foreground I do not want my video to be resumed. I tried to pause the MPMoviePlayerController in the method applicationWillEnterForeground. But, I think they resume implicitely after call to applicationWillEnterForeground. Is there any notification methods that corresponds to applicationDidEnterForeground OR applicationWillEnterBackground?
Although as you know UIApplicationDidEnterForegroundNotification and UIApplicationWillEnterBackgroundNotification do not exist, there are functions that correspond to the same thing.
They are,
UIApplicationDidBecomeActive:
and
UIApplicationWillResignActive:
Check out the UIApplication Class Reference here: https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728
In the notifications section of that document, you'll find the notifications posted to the Notification center. Your class can register to receive these notifications and handle the video playback state appropriately.
Hope this is the answer you were looking for.

Resources