iOS: aiff quiet on ipad 2 and 3 - ios

Three buttons triggering three AVAudioPlayers, identical code, identical sound files except for some pitch shifting.
All three sounds loaded thus:
NSString *pathDigitClick = [[NSBundle mainBundle] pathForResource:#"tickLoVol" ofType:#"aiff"];
_playerDigit=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathDigitClick] error:NULL];
[_playerDigit prepareToPlay];
And played so:
[_playerDigit play];
All three the same volume on iPad1, as they should be, but one of the aiffs sounds much quieter on the iPads 2 and 3.
I solved it by using another aiff, but I'd still like to know how it happens that the problem only occurs on the newer iPads.

Related

Objective-C MPMoviePlayerController iOS7 issue

I've seen this mentioned a few places around the web but have yet to find a concrete answer anywhere.
I'm trying to update an app so that it runs properly on iOS7. Part of that involves running a full-screen .mp4 video file (15.4mb / 40 Seconds long). Here is the code i use to setup the video, which runs fine in iOS6:
videoPlayer= [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: [[NSBundle mainBundle]pathForResource: [NSString stringWithFormat:#"introIpad"] ofType:#"mp4"]]];
videoPlayer.fullscreen = YES;
videoPlayer.movieSourceType = MPMovieSourceTypeFile;
videoPlayer.view.frame = self.view.bounds;
[self.view addSubview:videoPlayer.view];
[videoPlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoFinished) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer];
As mentioned above this code ran perfectly on iOS6, however on iOS7 it now gives me the following error log:
_itemFailedToPlayToEnd: {
kind = 1;
new = 2;
old = 0;
}
I've seen a few people saying that all they had to do is change the name of the video files so i've tried that with no luck. I also found some people mention the movieSourceType being a problem but i've tried to set it to "MPMovieSourceTypeStreaming" and that didn't work either.
Bit of a frustrating one and any help someone can give me would be greatly appreciated!
Thanks in advance.
So it seems that this issue is a generic response when the device cannot play the video file.
I've tried with different encodings and multiple types of video without much luck.
However I've just tried a video with a different dimension and it plays, my original video file was 1536x2048 (iPad Retina resolution) and it doesn't like it. I've re-rendered the video out at 768x1024 (Half the original size) and it works perfectly.
It's not a very useful error log but i guess if you have the same problem as me then try as many different types of video and find the one that works.

Play audio file multiple times after a very short time?

I have an audio file that is 2 seconds long. Im trying to play that many times before it is done playing. But when I try it with AVAudioPlayer by creating a new instance of it, it sounds like it stops the audio that was played before and plays the new one instead of playing them at the same time. Should I use another way to play sounds or is this not achievable?
Code:
NSURL *url = [[NSBundle mainBundle] URLForResource:#"PistolShootSound" withExtension:#"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[audioPlayer play];
audioPlayer is declared in the header file.
Have you used AVAudioPlayer's property numberOfLoops to play audio file repeatedly?
UPDATE: I didn't understand your goal before. If you want to play short files many times you could use AudioServices. Here is a good example of how to use it.

AudioServicesPlaySystemSound Volume on iPad

in my application I use AudioServicesPlaySystemSound to play little caf files.
When run my app on the iPhone and I change volume by lateral buttons, the app's sound changes
too, but on iPad the sound's volume in my app is always the same.
Maybe because on the iPhone is the ring volume, instead on the iPad is device volume.
How can I obtain same iPhone behavior on iPad?
Excuse me for my bad English....
I had the same problem but if you change the system sounds volume with buttons all the system sounds will be modified along with your app's. I found this really annoying.
The solution is to use AVAudioPlayer in place of AudioServices: as easy, but way more versatile. And there you can finely tune the volume for each sound, programmatically.
NSURL *soundurl = [[NSBundle mainBundle] URLForResource: #"mysound" withExtension: #"caf"];
AVAudioPlayer *mySoundPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:soundurl error:&error];
mySoundPlayer .volume=0.4f; //between 0 and 1
[mySoundPlayer prepareToPlay];
mySoundPlayer.numberOfLoops=0; //or more if needed
[mySoundPlayer play];

Play Multiple Videos from one page

Ok, so I am creating a basic iPad app that needs to play 4 videos. Videos need to be accessed from the same page.
I have one page/landing screen with an image that I have placed 4 Round Rec Buttons on. The MediaPlayer/MediaPlayer.h framework works perfectly, exactly what I want. But right now all four buttons play the same video, mainly because there is only one set of code but that is my problem. I assumed that repeating the code would allow me to replace the pathForResource:#"Beginning_Bumper" ofType:#"m4v" section of code but I get re-implimentation errors and the build fails. I've tried looking for other apps or tutorials online with no results. Also thought this question was my answer, but nothing there.
Here is the code I have, without duplication. So this code just plays one of the videos. Hopefully all of that makes sense, but feel free to ask more questions.
#import "Video_Presentation1ViewController.h"
#implementation Video_Presentation1ViewController
-(IBAction)playvideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Beginning_Bumper" ofType:#"m4v"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];playerController=nil;
}

iOS audio samples play only on earphone output

I'm developing a program that plays a short sample when a button is pressed. The problem is that it only plays through earphone output and not through the device's speaker. I've tried .wav and .aiff and AVAudioPlayer and SystemSoundID. On the simulator I can hear the sound. I'm using iPod Touch 4th gen. running iOS 4.1. Example code:
NSString *soundFile = [[NSBundle mainBundle] pathForResource:#"button" ofType:#"wav"];
NSURL *url = [NSURL fileURLWithPath:soundFile];
AudioServicesCreateSystemSoundID( (CFURLRef)url, &buttonID);
AudioServicesPlaySystemSound( buttonID );
Edit (solution found): I tried with another .wav file and it worked. Odd, because the original .wav's format is supported by iOS.
Sounds like you've solved the issue, but as a heads-up, you should only be using SystemSoundID style playback for user interface related sounds.
If the audio is a key part of your app, you need to set the appropriate AVAudioSession category and use (for example) the AVAudioPlayer playback methods.
Then again, this might not be relevant. :-)

Resources