Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 22, 2012, 01:31 AM   #1
Narendar Singh
macrumors member
 
Join Date: Jun 2012
Location: INDIA
Send a message via Skype™ to Narendar Singh
Sound is not playing on iOS 6 iPhone 5

The sound is not playing for

- 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.
__________________
Finite Disappointment Vs Infinite Hope
Narendar Singh is offline   0 Reply With Quote
Old Dec 28, 2012, 01:11 PM   #2
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
Quote:
Originally Posted by Narendar Singh View Post
The sound is not playing for

- 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?
__________________
.
CodeBreaker is offline   0 Reply With Quote
Old Jan 8, 2013, 05:02 AM   #3
Narendar Singh
Thread Starter
macrumors member
 
Join Date: Jun 2012
Location: INDIA
Send a message via Skype™ to Narendar Singh
Quote:
Originally Posted by CodeBreaker View Post
Do you by chance have an AVCaptureSession running with an audio input in it?
I did not understand
__________________
Finite Disappointment Vs Infinite Hope
Narendar Singh is offline   0 Reply With Quote
Old Jan 8, 2013, 08:19 AM   #4
xArtx
macrumors 6502a
 
Join Date: Mar 2012
Quote:
Originally Posted by Narendar Singh View Post
I did not understand
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 is offline   0 Reply With Quote
Old Jan 8, 2013, 09:22 AM   #5
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by xArtx View Post
Some png files weren't recognised across all devices...
png files?
__________________
dejo is offline   0 Reply With Quote
Old Jan 8, 2013, 10:26 AM   #6
xArtx
macrumors 6502a
 
Join Date: Mar 2012
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".
xArtx is offline   0 Reply With Quote
Old Jan 8, 2013, 11:04 AM   #7
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
If you always pay attention to case, you don't need to worry about it.

Quote:
The iOS-Filesystem is case-sensitive, whereas the OSX-Filesystem the Simulator uses isn't.
http://stackoverflow.com/questions/4...imulator-and-d
__________________
dejo is offline   0 Reply With Quote
Old Jan 8, 2013, 11:35 PM   #8
Narendar Singh
Thread Starter
macrumors member
 
Join Date: Jun 2012
Location: INDIA
Send a message via Skype™ to Narendar Singh
Quote:
Originally Posted by xArtx View Post
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:@"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
__________________
Finite Disappointment Vs Infinite Hope
Narendar Singh is offline   0 Reply With Quote
Old Jan 14, 2013, 12:38 AM   #9
xArtx
macrumors 6502a
 
Join Date: Mar 2012
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 by xArtx; Jan 14, 2013 at 12:52 AM.
xArtx is offline   0 Reply With Quote
Old Jan 17, 2013, 02:30 AM   #10
Narendar Singh
Thread Starter
macrumors member
 
Join Date: Jun 2012
Location: INDIA
Send a message via Skype™ to Narendar Singh
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.
__________________
Finite Disappointment Vs Infinite Hope
Narendar Singh is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:25 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC