Audio problem when building to device

Discussion in 'iOS Programming' started by mrarmalivia, May 24, 2009.

  1. mrarmalivia macrumors newbie

    Joined:
    May 24, 2009
    #1
    My first post, so I hope I get this right.

    I am able to build an application and test it under the simulator with the audio working correctly. However, when I go to build it on the device, the audio does not work.

    To further complicate matters, I built a second application using the same exact audio code, sound file, framework and device and when that builds, it functions properly on the device.

    The following is a collection of relevant snippets and further description of the code.

    Code:
    #import <AudioToolbox/AudioToolbox.h>
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	NSString *path = [[NSBundle mainBundle] pathForResource:object.file ofType:@"mp3"];
    	SystemSoundID soundID;
    	AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    	AudioServicesPlaySystemSound (soundID);	
    }
    
    The individual UITableViewCells are custom files that I put in place for text formatting purposes. To try some other things, I set a hidden background button that would trigger a method to play the sound which worked in the simulator, but failed on the device as well. This has since been removed for the original setup.

    The audio framework is currently:
    /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks/AudioToolbox.framework

    It is set to be Relative to Current SDK.

    I have had success with other applications using both iPhoneOS and iPhoneSimulator and have tried both with no success on this application.

    The audio files are stored under Resources and are assigned to be relative to enclosed group. I have tried project as well with no success.

    Running the code in debug mode while on the device confirms that all code is being run and that proper variable assignments have been made.

    Despite all of this, there is still no sound :(

    And yes, the volume is not muted!

    Thanks for any assistance.
     
  2. mrarmalivia thread starter macrumors newbie

    Joined:
    May 24, 2009
    #2
    I managed to work around the problem by replacing the code from the previous post with this.

    Code:
    #import <AVFoundation/AVFoundation.h>
    
    NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp3"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [theAudio play];
     

Share This Page