43917

Sound working in emulator, not in real iPhone

Have few short <strong>sound effect</strong> samples, which play <strong>just fine in emulator, but not at all in real iPhone</strong> 3GS. Here's the code, about as-is from Apple SysSound sample:

CFBundleRef mb = CFBundleGetMainBundle (); CFURLRef soundFileURLRef = CFBundleCopyResourceURL (mb, CFSTR("mySound"), CFSTR ("caf"), NULL); SystemSoundID sid; AudioServicesCreateSystemSoundID(soundFileURLRef, &sid); AudioServicesPlaySystemSound(sid);

When using iPhone, I can hear keyclicks and music from iTunes (not trying to use at same time as playing my sound) - but cannot hear my sound at all. Vibra works ok, so even Framework should be set up correctly.

Tried even the SoundEffect.h/m sample code, no change. Used same sound files, but shouldn't CAF be ok, especially when it plays in emulator?

What can I try next?

Answer1:

Try converting to a different format such as wav or mp3, then play again. If you want to use caf, Make sure you are formatting the caf correctly in Terminal.app:

afconvert -f caff -d ima4 mysound.wav

Answer2:

Just as a sidenote - I was having the exact same problem and spent probably close to an hour on converting files to the correct format, etc.. Yet the problem was the "mute" switch on the iPad. So even though the volume was up, and I could hear other sounds on the iPad, because the mute switch was turned on, it wasn't playing system sounds.

To add to the confusion, this app uses text-to-speech and the volume coming from the transcription was perfectly fine, it was only the sounds coming from AudioServicesPlaySystemSound() that I couldn't hear.

Answer3:

kind of a long shot, but remember that the phone's file system is case sensitive, while the mac's usually isn't. Double check your file name

Answer4:

Found an easier solution: <strong>use AIF sound files</strong>:

    <li>Click iTunes > Preferences</li> <li>Click on "General" tab</li> <li>Click "Import Settings" button</li> <li>In "Import Using" dropdown, choose "AIFF Encoder"</li> <li>Save your changes</li> <li>Select your sound files and choose "Create AIFF version"</li> </ul>

    Here's code I'm using, together with SoundEffect.h and SoundEffect.m from <strong>Apple sample BubbleLevel:</strong>

    NSBundle *mainBundle = [NSBundle mainBundle]; buzzerSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"buzzerSound" ofType:@"aif"]]; [buzzerSound play];

    Now same code - and sound effects - <strong>work in both emulator and hardware</strong>. Btw don't forget to switch back your original iTunes settings!

Recommend

  • Loop sound in java directory
  • How do I make a movie for upload to YouTube from a series of PNG images on the iPhone? [closed]
  • Detect hard taps anywhere on iPhone through accelerometer
  • 'System.InvalidOperationException' using xnaFramework to play a sound effect in windows ph
  • nullReferenceException when i try to play a sound effect?
  • send data with push notification - not returning whole push either
  • Strange in ShakeGesture Library on Windows Phone Application
  • Saving and accessing audio recordings
  • HTML editor for iOS [closed]
  • Unity iOS Build size is way big
  • Core Data and iTunes File Sharing - Move/hide the .sqlite file on app update?
  • iOS - How to access the device's file library?
  • Add a div to replace Video after Video Plays Through
  • Converting raw frames into webm live stream
  • Error while re-opening sound file in python
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Implementing “partial void” in VB
  • Multicolored edittext hint
  • Redux Form - Not able to type anything in input
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • What's the purpose of QString?
  • How can I sort a a table with VBA with given text condition?
  • Limiting recursion to certain level - Duplicate rows
  • All Classes Conforming to Protocol Inherit Default Implementation
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Calling of Constructors in a Java
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • Traverse Array and Display in markup
  • Transpose CSV data with awk (pivot transformation)
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Qt: Run a script BEFORE make
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory