How can I stop playing a movie?
I want to stop a playing a movie, when I use MPMoviePlayerController to play a movie.
Just use [movieController stop], should do the trick. It's defined in the MPMediaPlayback Protocol.
Related
I am using MPMoviePlayerViewController for playing the sound and video. I am streaming the song from the url. It is working fine.But the problem is, MPMoviePlayerViewController is not showing the time progress for the song I playing. That bar is disabled. How to make the time progress bar active? I have following code to play the song.
mediaPlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:songUrl];
[self presentModalViewController:mediaPlayerController animated:YES];
[[mediaPlayerController moviePlayer] play];
If you want to show the current progress time on your own custom way, you can show it by using the currentPlaybackTime property in the MPMediaPlayback protocol gives you that info.
U use AVPlayer for playing live streaming. Refer this link.
Also refer StitchedStreamPlayer link sample code by apple.
Set controlStyle for mediaPlayerController:
[mediaPlayerController moviePlayer].controlStyle = MPMovieControlStyleFullscreen
My app plays video file without sound. And it interrupts any playing music in backgroud (iPod app for example). How do not interrupt audio session of other apps if it's possible.
My video file is without sound. To play video i use MPMoviePlayerController.
EDIT: Here is my video player code:
_player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
[self installMovieNotificationObservers:nil];
[_player setShouldAutoplay:YES];
[_player setUseApplicationAudioSession:NO];
[_player.view setFrame:self.navController.view.frame];
[_player setMovieSourceType:MPMovieSourceTypeFile];
[_player setRepeatMode:MPMovieRepeatModeNone];
[_player setFullscreen:YES animated:YES];
[_player setControlStyle:MPMovieControlStyleNone];
[_navController.view addSubview:_player.view];
[_player play];
Directly from Apple's docs:
http://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html#//apple_ref/occ/instp/MPMoviePlayerController/useApplicationAudioSession
useApplicationAudioSession
A Boolean value that indicates whether the
movie player should use the app’s audio session.
#property (nonatomic) BOOL useApplicationAudioSession Discussion The
default value of this property is YES. Setting this property to NO
causes the movie player to use a system-supplied audio session with a
nonmixable playback category.
Important In iOS 3.1 and earlier, a movie player always uses a
system-supplied audio session. To obtain that same behavior in iOS 3.2
and newer, you must set this property’s value to NO. When this
property is YES, the movie player shares the app’s audio session. This
give you control over how the movie player content interacts with your
audio and with audio from other apps, such as the iPod. For important
guidance on using this feature, see “Working with Movies and iPod
Music” in Audio Session Programming Guide.
Changing the value of this property does not affect the currently
playing movie. For the new setting to take effect, you must stop
playback and then start it again.
Availability Available in iOS 3.2 and later. Declared In
MPMoviePlayerController.h
Swift 5 answer
do {
if #available(iOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: AVAudioSession.Mode.default, options: .mixWithOthers)
} else {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, options: .mixWithOthers)
}
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}
i am using MPMusicPlayerController in my app and when i enter to background it stop playing.
this is how i add it :
musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
The iPodMusicPlayer is always enabled in the background. You shouldn't have to set anything. And [MPMusicPlayerController applicationMusicPlayer] won't play in the background ever. I'd say you're using the wrong MPMusicPlayerController somewhere.
You need to indicate in your app's plist file that you want to play audio in the background.
you create the applicationMusicPlayer it is not play in back ground.
you have to create ipodMusicPlayer to overcome this.
check this out for further refference.
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMusicPlayerController_ClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008221
I want to play two video in iPhone simultaneously.
There are two way to play video in iphone, One is use AVQueuePlayer. but in this controller I don't get how get the video playing is completed and how to restart video again.
Another way is MPMoviePlayerController . but in this controller I don't get how to seek video at particular time and also it is not able to play two video simultaneously as the AVQueuePlayer is able to play.
as a solution i am using AVQueuePlayer to play video and but can any one help me to restart video and get method to detect end point of the video. or know any other api to so this
Thanks in advance.
I have found the solution to play two video . You can use AVQueuePlayer to play video. Using this controller you can play two video at the same time .
I wonder if this is even possible. Video playback on the iPhone is ensured thanks to a hardware video decoder. And I really think the hardware decoder can only handle one video stream at a time.
Ecco is correct. You're limited to one video at a time due to hardware restrictions.
However, if you're after 7KV7's suggestion of one video ending and triggering the playback of another, you can make use of the MPMoviePlayerPlaybackDidFinishNotification notification in the following way:
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(firstMoviePlayerDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
- (void)moviePlayerDidFinish:(NSNotification *)notification {
if (firstMovie) {
[moviePlayerController setContentURL:nextMovieURL];
[moviePlayerController play];
} else {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}
Also, note that you can find the current playback point in a MPMoviePlayerController instance by examining the currentPlaybackTime property.
When I open a UIImagePickerController, I can display the device's camera input stream.
But when I play an AVAudioPlayer with [player play] then the camera stops working.
How can I deal with that?
you can't because UIIMagePickerController is controlling the audio, you will need to use low level AVFoundation in order to do that.
checkout AVCam sample code how to record a movie and add the view as subview , that way you will stay in control of the audio and will be able to play audio.