Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Narendar Singh

macrumors member
Original poster
Jun 22, 2012
76
0
INDIA
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.
 

CodeBreaker

macrumors 6502
Nov 5, 2010
494
1
Sea of Tranquility
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.

Do you by chance have an AVCaptureSession running with an audio input in it?
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
I did not understand :rolleyes:

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?
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
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".
 

Narendar Singh

macrumors member
Original poster
Jun 22, 2012
76
0
INDIA
Some png files weren't recognised across all devices because I didn't pay attention to case. Is your sound file .wav or .WAV?

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
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
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.
 
Last edited:

Narendar Singh

macrumors member
Original poster
Jun 22, 2012
76
0
INDIA
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.