i put a movie when my application will lunch . just like gameloft games .
so when application has lunched , movie plays fine but before the move plays .. my FirstViewController xib file show first then moview start to play ! why ?
here is my code :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"movie" ofType:#"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
IntroMovie.movieControlMode = MPMovieControlModeHidden;
[IntroMovie play];
}
Your question is a little unclear, but what I think you are asking is why your movie is not playing when the application launches before the user sees the controls and items in your XIB file. If this is correct, then this is the normal behavior as typically the application will launch and only then call the function you have (applicationDidFinishLaunching). There is no guarantee that you will get that function called before the controls have loaded and are viewable on the screen all the time.
It is bad form to start you application with a movie, but if you want to then you have to deal with the fact that there will potentially be a default image or even your controls that you put in your XIB file.
One way to start with a movie, is that you must hide or delete everything in the XIB file so the screen will appear blank when the application loads. Then, when you application calls the applicationDidFinishLaunching function the user will not have seen your application and the first thing they will see is the movie. When the movie is finished playing, you will need to have a notification listener instruct your application to show the controls for your application or switch to another XIB file that has the app controls within it.
I hope this helps.
Related
I play a sound in viewDidLoad now when user push home button sound paused.when user run app again sound play from place that paused before.how can i stop it(no pause) when user push home button?
Have a look into the application delegate methods:
- (void)applicationDidEnterBackground:(UIApplication *)application
- (void)applicationWillResignActive:(UIApplication *)application
You may place code there that gets run, when your app is closed. Try keeping a pointer to you AVAudioplayer around and "stop" its currently playing content if necessary.
Be sure to restart it when the user comes back!
The documentation on the "UIApplicationDelegate Protocol Reference" helps :)
NSString *path = [[NSBundle mainBundle] pathForResource:#"*" ofType:#"mp3"];
If you use * in the place of the mp3 name the music will be stopped.
I am playing a wav file to give a little audio feedback when a button in my UI is pressed. My question is when you first press the button there is a delay (about 1.5secs) whilst the sound file "sound.wav" is loaded and cached. Is there a way to pre-cache this file (maybe in my viewDidLoad)? I guess I could do it by just playing it a viewDidLoad, but would really need to disable the audio so it does not "beeb" each time the app starts.
many thanks for and help.
gary
EDIT_001:
Looks like my question is a duplicate of this post unless anyone has any new info? Maybe a way to turn the play volume down temporarily, unless the audio is cleared each time through the run loop.
EDIT_002:
I am currently using SystemSoundID / AudioServices:
-(void)playButtonSound {
NSBundle *bundle = [NSBundle mainBundle];
NSString *soundPath = [bundle pathForResource:#"buttonClick_002" ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundPath], &soundID);
AudioServicesPlaySystemSound(soundID);
}
Use performSelectorInBackground:#selector(<A SELECTOR>) when the view loads to load the wav file into memory. Then play the sound when needed ;)
Hope this helps!
In the end I actually found that using AVAudioPlayer allowed my to do the preload that I required using (see below) in viewDidLoad to do the preload:
[audioPlayer prepareToPlay];
and then using (see below) in the button methods where I needed the sound to play on demand.
[audioPlayer play];
gary
I'm using Page Control example from Apple. I want to be able to scroll horizontally to certain page and get the sound automatically play when viewing that page? And then sound stop when viewing the other page?
So, for example. On page 1, i have some texts. When i go to the next page which is on page 2, i want sound to be automatically play and stop when i go to page 3.
I'm planning to use If statements (since it's not that many pages) to determine which page will get the sound.
My question is simple. How do you get the sound play automatically when viewing certain page?
By the way, I'm planning to use System Sound.
I know how to play the sound using button. But how do you get it automatically - start when certain page appear and stop when moving to the next page.
Thank you in advance!
Edited:
I put in this code in ViewDidLoad but the sound played on sooner before it reach the page intended:
// Set the label and background color when the view has finished loading.
- (void)viewDidLoad {
pageNumberLabel.text = [NSString stringWithFormat:#"Page %d", pageNumber + 1];
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
if (pageNumber == 3) {
NSString *path = [[NSBundle mainBundle] pathForResource:#"crunch" ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
}
}
Why cant you make the sound go off when your desired viewControllers view goes on screen? You know when it goes on screen from the scrollViewDidScroll method and loadPage method (in the Page Control example). By looking at the methods in there you should be able to identify when you need to play the sound (because the specific view has come on the screen) and play it. Another approach would be to subclass UIViewController with something like UISoundViewController and have it play the sound on viewDidLoad.
-viewDidLoad is called once and only once* when the view controller's view property is loaded. You only add stuff that is called once and only once in this method.
Playing sound clearly isn't a once-and-only-once event. Put those into -viewDidAppear:.
*: Unless the view controller is deallocated.
I am implementing some audiobooks for iPhone. I used AVFoundation. Something like this:
NSString *path = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mp3"];
player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
I have a problem. When the screen goes dark (single audio files can be very long) the audio stops playing.
I solved this problem with this string of code
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// something else here...
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
This does not allow the iPhone to "sleep". However you can guess how this is foolish: your battery level goes down in minutes and this is not possible by audiobooks lasting more than 20 hours, for example...
So, do you know a way to prevent that when the screen sleeps the AVAudioPlayer does not stop playing?
Thanks...
Fabio
Set your audio session to kAudioSessionCategory_MediaPlayback to playback while the screen is locked.
Could I suggest that once you start playing the audio file that you tell the user to press the power button (not home button) which will lock the phone. It will not close you app but it will power off the screen with you application running in the background. Currently several apps do this.
When I use my app (on the device), the actual volume works OK for a while, but after a few days it seems to get 'stuck' at a low level.
Adjusting the volume rocker has no effect - and it shows 'Ringer' text. I've noticed that other people's apps are similarly affected if they show the 'Ringer' text when adjusting the volume. But apps which don't show 'Ringer' text are not affected by this.
How would I remove the 'Ringer' text and get my app to respond properly to different volumes?
I found some code on Apple's forums which fixes it. You have to use the AVFoundation.framework and put a bit of code into your app delegate. And put an audio file called 'blank.aif' into your project. Basically, it's a hack which prepares a file to play, but then never plays it. This fools the system into thinking that sound is being played all the time, which allows the user to use the main volume control.
#import <AVFoundation/AVFoundation.h>
//...
-(void)applicationDidFinishLaunching:(UIApplication *)application {
//volume control hack
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"blanksound" ofType:#"aif"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];
AVAudioPlayer *volumeHack = [[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]retain];
[fileURL release];
[volumeHack prepareToPlay];
// other applicationDidFinishLaunching stuff
}