I am using following code to show video file in initial state.But when i launch app it start playing without giving me option to play.how i can achieve that
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"En_annan_resa_Master_ENG_PC" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
movie_obj = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[movie_obj.view setFrame:CGRectMake(1024*i, 0, 1024, 748)];
movie_obj.scalingMode=MPMovieScalingModeAspectFit;
[self.scrollView addSubview:movie_obj.view];
[movie_obj prepareToPlay];
I am expecting when i launch app it show mw video view and show control to play do not play automatically.
thanks for your help
check below answer
https://stackoverflow.com/a/15701076/1713478
just replace NO to En_annan_resa_Master_ENG_PC
try this your problem will solve
Related
I managed to create this application that includes an animation in it. But I want to make it stand out and more fun by adding a .wav file that I downloaded from the web. I want the sound to play for the duration of the animation. Only started coding a month ago so any help would be deeply appreciated
You could use the AVAudioPlayer
just create a method and connect it to your button or animation
-(void) playLoopingMusicInApplication {
AVAudioPlayer *audioPlayer;
// set the pathForResource: to the name of the sound file, and ofType: to AAC preferrably.
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"fileName" ofType:#"WAV"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.delegate = self;
//infinite
player.numberOfLoops = -1;
[player play];
//[player release];
}
PS - You will need to get the AVFoundation framework, and the AudioToolbox framework in your project
hope this helps!
First time i am capturing video in my App, but when i start capturing i want that button click sound as native application. I have searched a lot and came to know that it is a system sound. Can anyone please tell me how can i add that sound in my application when i start capturing video and when i stop capturing.
Currently i am using AVAudioPlayer to play sound as shown below
NSURL *url1 = [[NSBundle mainBundle] URLForResource:str withExtension:#"wav"];
_startAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url1 error:nil];
_startAudioPlayer.delegate= self;
[_startAudioPlayer prepareToPlay];
[_startAudioPlayer play];
Thanks in advance.....
Just import AudioToolbox.framework.
Create the URL for the source audio file
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: #"tap"
withExtension: #"aif"];
// Store the URL as a CFURLRef instance
self.soundFileURLRef = (CFURLRef) [tapSound retain];
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (
soundFileURLRef,
&soundFileObject
);
Play sound
AudioServicesPlayAlertSound (soundFileObject);
Here is a nice tutorial link you can follow this
When you want to start capturing video at that time call this bellow method like this...
[self playSound];
use my this bellow method for play sound...
-(void)playSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"adriantnt_release_click" ofType:#"mp3"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
first store any mp3 or any audio file in your project folder For Ex: i add adriantnt_release_click.mp3 file.
Also add AVAudioPlayerDelegate in your .h file and add AudioToolbox.framework in your project..
After the app starts, and I press the start button, it s "lagg" but I used this code into viewdidload and viewdidappear too:
gombhang = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"button4" ofType:#"mp3"]];
gombha = [[AVAudioPlayer alloc] initWithContentsOfURL:gombhang error:nil];
[gombha prepareToPlay];
gombha.delegate = self;
How can I fix this lagg? If I can t fix it apple will reject it?
As I know Audioplayer takes few seconds to load the audio file .
NSString *soundFile = [[NSBundle mainBundle] pathForResource:#"button4" ofType:#"wav"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFile]; AudioServicesCreateSystemSoundID((CFURLRef) CFBridgingRetain(soundFileURL), &_MySound); AudioServicesPlaySystemSound(_MySound);
And another way: I made an empty/ muted 0.1 sec sound file, and played in viewdidload, and this method loaded the avaudioplayer before I clicked on the start button, so it doesn t lagg anymore.
I am trying to play a MP4 file from my resources , but its not playing . ... what else i have to do . Help me to fix this ....
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"line.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 300, 400);
[moviePlayer play];
Make sure that your movie file is not only listed in your Project Explorer, but also included in your "Copy Bundle Resources" list.
You can check by clicking on the root node in project explorer, select your target, and then click on the "Build Phases" tab. Once doing that, you should see four lists, the second one is your "Copy Bundle Resources" list. You can use the search field in the Build Phases tab to quickly see if your movie is included in this list. If it is not, drag and drop your movie file to this list.
I'm currently using Xcode 4.3.2, but these steps haven't change in a while. Hopefully these steps help.
Try instead of
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"line.mp4" ofType:nil];
this:
NSString *urlStr = [[NSBundle mainBundle] pathForResource:#"line" ofType:#"mp4"];
I want to play an audio file which is posted on a website. I'm trying to use AVAudioPlayer and set the url to its website link. But the bgPlayer turns out to be nil. I think I can download this audio file and play it afterwards, but is there any way to play it while I'm downloading it?
NSURL *bgURL = [NSURL URLWithString:#"http://www.radioslots.com/iphone/test/tmp/1.mp3"];
bgPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:bgURL error:nil];
bgPlayer.numberOfLoops = -1;
if (bgPlayer) {
[bgPlayer play];
}
AVAudioPlayer isn't made to open network streams, I could be mistaken but I'm pretty sure it's not possible.
Just off the top of my head, I can think of two ways that would probably work:
1. Use MPMoviePlayer, as this can open network streams and despite the name works with audio. The only thing is this pops up the modal player with controls.
2. Download the network file and store it locally, then use AVAudioPlayer to play the local file.
I have just written answer here.Check it and replace the url used there with yours..
you just replace
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"songname" ofType:#"mp3"];
NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
with
NSString *soundFilePath = #"Your URL";
NSURL *newURL = [[NSURL alloc] initWithString: soundFilePath];
There is a proper documentation available at this link
But I think you should also check the error code you are getting by this way:
NSError *error;
bgPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:bgURL error:&error];
Hope this helps.