Sound is not playing on iOS 6 iPhone 5

Discussion in 'iOS Programming' started by Narendar Singh, Dec 21, 2012.

  1. Narendar Singh macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #1
    The sound is not playing for :confused:

    - iOS 6 iPhone 5
    - iOS 5 iPhone 4

    but working fine on iPad 2 and iPhone 3GS :)

    Code:
    - (void)playSound
    {
        // read the sound file from resources and play it on successful scanning
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"scan_beep" ofType:@"wav"];
        NSURL *fileURL = [NSURL fileURLWithPath:filePath];
        AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &systemSoundID);
        AudioServicesPlayAlertSound(systemSoundID);
    }
    What can be wrong here, same code is working for few device but not for all.

    I call the above function when I scan the barcode in my sample app.
     
  2. CodeBreaker macrumors 6502

    Joined:
    Nov 5, 2010
    Location:
    Sea of Tranquility
    #2
    Do you by chance have an AVCaptureSession running with an audio input in it?
     
  3. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #3
    I did not understand :rolleyes:
     
  4. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #4
    This works for me:
    Code:
           NSURL *path   = [[NSBundle mainBundle] URLForResource: @"scan_beep"
                                                        withExtension: @"wav"];
            self.soundFileURLRef = (__bridge CFURLRef) path;
            AudioServicesCreateSystemSoundID (
                                              soundFileURLRef,
                                              &beep
                                              );  
    
    Some png files weren't recognised across all devices because I didn't pay
    attention to case. Is your sound file .wav or .WAV?
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    png files?
     
  6. xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #6
    Loading png (image) files from main bundle to a UIImage has on more
    than one occasion, worked on one device/iOS and not another for me.
    I had to change
    Code:
    UIImage *myImage = [UIImage imageNamed:@"Sun.png"];
    
    to
    Code:
    UIImage *myImage = [UIImage imageNamed:@"Sun.PNG"];
    
    to see the image on all three devices. The file name was "Sun.PNG".
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
  8. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #8
    Well my file is beep.wav and in code I am using ofTpye:mad:"wav"

    Very strange, same code is running perfect in iPad 2, iPod Touch 4th Gen, iPhone 3GS but not in iPhone 4 and iPhone 5
     
  9. xArtx, Jan 13, 2013
    Last edited: Jan 13, 2013

    xArtx macrumors 6502a

    Joined:
    Mar 30, 2012
    #9
    Try:

    Code:
    AudioServicesPlaySystemSound (systemSoundID);
    
    rather than:

    Code:
    AudioServicesPlayAlertSound(systemSoundID);
    
    Also, the rest of your code belongs in a function that is called only once at
    program launch rather than loading the sound to memory every time you
    play it.

    EDIT,,
    Also on the iPhone 4 & 5, try:

    Code:
    AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
    
    This should invoke a vibration on those devices, but does not rely on any sound file being loaded.
     
  10. Narendar Singh thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #10
    Tried whatever you guys suggested !!

    let me remind my issue, with following code I test my application on following devices:

    - iPhone 5 iOS 6
    - iPhone 4S iOS 6
    - iPhone 4 iOS 5
    - iPad 2 iOS 5
    - iPhone 3GS not remember its iOS Version

    Code:
    - (void)playSound
    {
        // read the sound file from resources and play it on successful scanning
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"scan_beep" ofType:@"wav"];
        NSURL *fileURL = [NSURL fileURLWithPath:filePath];
        AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &systemSoundID);
        AudioServicesPlayAlertSound(systemSoundID);
    }
    Then I run my Application, sound works for iPhone 4S, iPad2 & iPhone 3GS but not for iPhone 5 & iPhone 4.
     

Share This Page