My ios app plays few audio (.m4a) files . It works well and i hear the audio on ios simulator running on ios 7, but when i run the app on my iphone 5, ios 7, it does not play the audio. At least i don't hear anything.
I ran the app on iPhone 4s , os 6.3 and 7.0 and it worked well. Looks like the issue is something related to iPhone 5, maybe it is some setting in my phone ?
I did a similar post here but its not really helping me.
Audio file doesn't play in iPhone 5
In the play audio method, i have the following statements
I have audioPlayer loaded and ready to play on a swipe gesture
self.audioPlayer = [self getAudioPlayer:imgAudFileName extension:#".m4a"];
[self.audioPlayer prepareToPlay];
When the use clicks on play button, this is the action that gets executed
- (IBAction)playOrPauseSound:(UIButton *)sender {
[self.audioPlayer play];
BOOL isAudioPlaying = [self.audioPlayer isPlaying];
NSLog(#" Audio Playing? %d", isAudioPlaying);
[self.audioPlayer setDelegate:self];
}
which returns 1 for both Simulator and iPhone5
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player
successfully:(BOOL)flag {
NSLog(#" Did Finish Playing %d", flag);
}
delegate method is also returning 1 on iPhone 5..
Any help on this is appreciated.
Thanks,
Update : Nov-12
I tried using a different method to initialize and use AudioPlayer but the issue remains the same
- (IBAction)testAction:(id)sender {
NSURL *url = [[NSBundle mainBundle] URLForResource:#"hello" withExtension:#"m4a"];
_somePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
_somePlayer.delegate = self;
[_somePlayer play];
}
I deployed the app on my friends iPhone 5, ios 7 and it worked there without any issues. I dont have a proper explanation for why it's not working on my phone. I guess I have to get it tested on more iphone 5.
Thanks,
Related
i am having issues with playing a video through url using avplayer and avplayerviewcontroller
it plays fine on simulator but doesnt work on device.
Is it a problem with the static ip i have been using as follows -
https://ipaddress(111.111.11.11:443)/mc/images/wall/small.mp4
same video from the following url plays fine on device
http://techslides.com/demos/sample-videos/small.mp4
the code below i am using -
NSURL *url = [NSURL URLWithString:#"http://techslides.com/demos/sample-videos/small.mp4"];//#""];https://180.179.77.47:443/mc/images/wall/small.mp4
AVAsset *videoAsset = [AVAsset assetWithURL:url];
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:videoAsset];
playerVideo = [AVPlayer playerWithURL:url];
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionModeMoviePlayback error:nil];
movieController = [[AVPlayerViewController alloc]init];
[movieController setAllowsPictureInPicturePlayback:YES];
movieController.player = playerVideo;
movieController.delegate = self;
movieController.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self presentViewController:movieController animated:YES completion:nil];
I was also facing the same issue short while ago, but just now observed that my device was on silent mode & hence it was running video without sound.
But it should not have happened. If I run YouTube app & plays video, it works fine even if device is on silent mode.
I found the answer. Following is the Swift 3 code. If you set the category to AVAudioSessionCategoryPlayback and if the device is on silent mode then the app plays video with sound.
If you set the category to AVAudioSessionCategoryAmbient, and if you run the app on device with silent mode on, then the app will play the video without sound.
let audioSession = AVAudioSession.sharedInstance()
do
{
try audioSession.setCategory(AVAudioSessionCategoryPlayback, with: .duckOthers)
}
catch
{
print("AVAudioSession cannot be set")
}
I think your video and your device are not withing same network. Used common network for both or put it at remote location from where everyone can access it.
You can play video in simulator because your system (mac) is connected with common network on which video is available but i think you are using different network for mobile network.
Hope this will help :)
AVAudioPlayer starts playing music when a local notification is shown to user. After clicking the notification and app runs in foreground I could not stop the music only in iOS 7.1.2. But I can stop it in iOS 8+.
Has anyone heard any iOS 7.1.2 bug about this issue reported by Apple?
I use the same instance that I start playing the music.
// start playing the music
[self.player prepareToPlay];
// Stop playing the music
[self.player stop];
[self.player setCurrentTime:0.0f];
For playing use:
[self.player prepareToPlay];
For pausing/stopping use:
if (self.theAudio.playing) {
[self.theAudio pause];
}
[self.theAudio stop];
self.theAudio.currentTime = 0;
I am using MPMoviePlayer to play video in my iPhone application.
I want play video in loop means wants to play single video repeatedly.
I am using following code to repeat the video:
MoviePlayer.repeatMode = MPMovieRepeatModeOne;
It is working properly on Simulator and higher phone But it is not working properly on iPhone 4.
It is not repeating the video on iPhone 4 Device
Is there any specific reason for that? is there any solution for that?
My iPhone is iPhone 4 with updated iOS 7
Thank you
This Solution I have implemented:
I have used MPMoviePlayerPlaybackStateDidChangeNotification this Notification
Added following notification to Movie Player
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinishedFromSetUnderway:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:MoviePlayer];
Notification Method:
-(void)moviePlayBackDidFinishedFromSetUnderway:(NSNotification *)dict{
if (dict.object == MoviePlayer) {
NSInteger reason = [[dict.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
if (reason == MPMovieFinishReasonPlaybackEnded)
{
[MoviePlayer prepareToPlay];
[MoviePlayer play];
}
}
}
Done !!! It is working properly now ... :)
In my application I am using an AVAudioRecorder object to allow the user to record a sound file, and when the user is done recording they can play the sound via the AVAudioPlayer. The issue I'm having is when the user tries to play the audio file it only plays for one second. What is even more odd is that this code worked perfect on iOS 5, but since upgrading to iOS 6 this issue has started to happen.
I have checked the file that is being created via iTunes file sharing, and I'm able to play the entire sound file on my desktop.
Below I have pasted the code from my manipulation file that loads the audio player. From what I can tell the
- (void)playRecordingBtnClk:(id)sender
{
NSLog(#"Play btn clk");
if (!isRecording) {
// disable all buttons
[_recordButton disableButton];
[_stopButton disableButton];
[_playButton disableButton];
[_saveButton disableButton];
// create the player and play the file from the beginning
if (audioPlayer) {
[audioPlayer release];
audioPlayer = nil;
}
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioRecorder.url error:&error];
audioPlayer.delegate = self;
audioPlayer.currentTime = 0.0;
[audioPlayer prepareToPlay];
if (error) {
NSLog(#"Error Playing Audio File: %#", [error debugDescription]);
return;
}
[audioPlayer play];
[self startTicker];
}
}
It appears that the
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
method is being called after one second which is why the audio player stops. Anyone have any ideas what is going on here?
For iOS 6.0, add two more lines:
soundPlayer.currentTime = soundPlayer.duration + soundPlayer.duration;
soundPlayer.numberOfLoops = 1;
Not a perfect solution. We may need to wait for iOS 6.0.1/6.1 update.
For more, please visit this, someone commented there, saying it might be a problem of CDAudioManager.
I have a piano application. It's working fine, with a little error. If I play several keys at the same time very fast, the sounds disappears for a couple of seconds, and receive the following message in the console
AudioQueueStart posting message to kill mediaserverd
Here is the relevant code:
-(IBAction)playNoteFromKeyTouch:(id) sender{
[NSThread detachNewThreadSelector:#selector(playNote:) toTarget:self withObject:[NSString stringWithFormat:#"Piano.mf.%#",[sender currentTitle]]];
}
-(void)playNote:(NSString *) note{
NSError *err;
NSString *path = [[NSBundle mainBundle] pathForResource:note ofType:#"aiff"];
AVAudioPlayer *p = [[AVAudioPlayer alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&err];
p.delegate = self;
if (err) {
NSLog(#"%#", err);
}else{
[p prepareToPlay];
[p play];
}
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
[player release];
}
I have tested with Instruments and I don't have any memory leak. If somebody could have an idea to avoid this error it would be appreciated.
I suffer from a similar issue.
I spent ages trying to solve the issue, and I think my particular issue takes place when:
I'm in an AudioCategory that doesn't allow sound to play while the mute switch is on.
I start to play a sound (I actually don't do this in the app, but this is how I can reproduce reliably).
With the sound still playing, I switch to another AudioCategory that doesn't allow sound to play while the mute switch is on.
From this point onwards, I get 'posting message to kill mediaserverd' from what looks like various points in calls in the AudioSession API. The app hangs, the device hangs, and I struggle to get the device back to a normal running state.
According to this message it's the device's mute switch.
It turns out that having the iPad muted via the device's physical switch was
causing the problem with my app. As long as the button is not
switched on the problem does not occur.
Sheesh. How to programmatically override?
I "solved" the issue using SoundBankPlayer instead of AVAudioPlayer. SoundBanker info.