movieURL = [NSURL URLWithString:#"http://122.165.71.249:6060/test/music/killbill.mp3"];
// Setup the player
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
I am using this code play online connection ,but i want offline also play in the video url link.
You will have to use an NSURLConnection to download the file yourself, you can then use the original URL for the movie player whilst downloading the video at the same time. When I did this I tried to get the video player to use the local file before I has finished, by delaying start of playback after a certain number of bytes have been received, but I found it would only work on the simulator but not on the actually iPhone/iPodTouch. If you do search for (MPMoviePlayerViewController "Nathan Day" Cache) you will see some example code I post on Apples Cocoa mailing trying to solve this.
Related
I’m building an application which supports both video playback and recording (not simultaneously, it’s just two separate features it provides). In order to make the videos play after the app enters background and gets back, I had to add an App plays audio item to Required background modes in the plist (I’m using MPMoviePlayerController for playback).
This, however, causes a problem with my video recording (I’m using UIImagePickerController for it). Basically, even after the picker is dismissed (either by the Cancel button or when it’s finished picking media), the app still keeps the audio recording session running.
If I remove the App plays audio item from the plist, the ImagePickerController’s audio session stops misbehaving, but then I can’t resume the playback of MPMoviePlayerViewController on switching to app from background mode.
Is there a way I can customise the handling of the audio session so that both the MPMoviePlayerController and UIImagePickerController can work properly?
yes, there is a way you can customize the handling of the audio session for what you desire: don't try to set the App plays audio setting.
instead, in your AppDelegate code (which is usually in AppDelegate.m from the simple wizard projects provided), supply code in the applicationWillResignActive: method that will stop the playback in your MPMoviePlayerController, and then use applicationDidBecomeActive: to resume the playback at the point at which you paused it if so desired.
this will not only allow the video to be resumed after a temporary pause, but it will allow you to save the state so that the video can be resumed in case the app is removed from memory or in case the user causes it to be quit.
You can scratch the background modes and instead use notifications to pause/resume your player. See UIApplicationDidBecomeActiveNotification and UIApplicationWillResignActiveNotification in the UIApplication class reference.
You can snag some code and see this implemented in this class. Here is some of the relevant code from that class:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_didBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(_willResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
- (void) _didBecomeActive:(NSNotification*)notification {
if (_wasPlaying) {
[_movieController play];
}
}
- (void) _willResignActive:(NSNotification*)notification {
_wasPlaying = _movieController.currentPlaybackRate != 0.0;
if (_wasPlaying) {
[_movieController pause];
}
}
im using a videoplayer - and realized that the "done" button seems to be labled with "done" even thogh i set "Localization native development region" to "Germany"
i tried a web video and there it was labled with "fertig"
maybe someone can help me with this.
the code snip is here:
MPMoviePlayerViewController *moviePlayer =
[[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackStateChange:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer.moviePlayer];
[mainVc presentMoviePlayerViewControllerAnimated:moviePlayer];
You can find the answer here: Localize Done button of MPMoviePlayerViewController
check the CFBundleDevelopmentRegion in your Info.plist
make sure you have the German version of InfoPlist.strings
change the language of your Simulator to German
I have got Audio Mixer(MixerHost) sample code from Apple iOS. This code is working fine.
It is playing the sample Audio files continuously. Can you tell me how to stop my Mixer code to stop after playing audio once?
Is it possible disable repeated play using AVAudiosession.
Do you have this method?
// Handle a play/stop button tap
- (IBAction) playOrStop: (id) sender
In MixerHostAudio.m, inside the inputRenderCallback method, just comment the line
if (sampleNumber >= frameTotalForSound) sampleNumber = 0;
Try to implement this inputRenderCallback as below:
if (sampleNumber >= frameTotalForSound) {
[[NSNotificationCenter defaultCenter] postNotificationName:NOTI_AUDIO object:nil userInfo:nil];
return noErr;
}
The NSNotification "NOTI_AUDIO" just let the viewcontroller know when the audio is stopped.
Hope this helps!
I'm currently showing a dailymotion url directly into a UIWebview.
When tapping on the thumbnail image, the video starts playing in fullscreen mode.
The problem is: when the video stops playing or the user tapps the "done" button, the original thumbnail has disapeared from the UIWebview, making it impossible to launch the video again.
I would like to control when the video has finished playing or the user has tapped the done button to reload the UIWebView.
I've been looking around and playing with the Notification center but I couldn't get any response, can you tell me what code I should use ?
loading the video
NSURLRequest *requestObject = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.dailymotion.com/embed/video/xh7cgv_cine-pocket-a-candidate_creation"]];
[self.webv loadRequest:requestObject];
notification catch
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidExitFullscreen:)
name:MPMoviePlayerDidExitFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayerDidEnterFullscreenNotification:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
thanks,
Louis
corresponding to this thread the MediaPlayer doesn't send out any notifications when started from within the UIWebView (no source given however). you could try these hacks: visible-hidden events hack, timed key window checking-hack, subview events-hack. If you had luck, please share some code!
I am using a music player property for iPod player controller.
// .h
#property (nonatomic, retain) MPMusicPlayerController *ipodPlayer;
// .m
ipodPlayer = [MPMusicPlayerController iPodMusicPlayer];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self selector:#selector(changedPlaybackState:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:ipodPlayer];
[notificationCenter addObserver:self selector:#selector(changedNowPlayingItem:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:ipodPlayer];
[ipodPlayer beginGeneratingPlaybackNotifications];
During background processing, if iPod player app is terminated, the console prints out:
MediaPlayer: Message playbackState timed out.
If it doesn't crash(or freezes, slowing performance), the notification is not being sent to my observing methods anymore. I can still send messages like:
[ipodPlayer pause];
[ipodPlayer play];
[ipodPlayer skipToNextItem];
[ipodPlayer skipToPreviousItem];
but can't receive any notifications
My questions are:
Is there are way to reassign, reload pointers during runtime? How can I restore the property to be just like when it's first launched?
How can I catch the messge:"MediaPlayer: Message playbackState timed out." in console output? This is not like using NSLog.
Thank you for helping me.
UPDATED:
It seems like using assign or weak for ipodPlayer property was the solution. Also, accessing it is done with assumption that the property may not be there. After many trials and a year of actually using it in my app, I think this was the right solution.
I had similar issue with my MpMoviePlayerController in iOS 5. I Found a fix that took care of it. It might work here as well.
Add:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
in viewDidLoad.
More my other post