Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

iphone - Couldn't play system sound after switching to iOS 5

This is how I played a beep sound effect in iOS 4:

SystemSoundId beepOnSoundId;

CFURLRef soundUrl = CFBundleCopyResourceURL(
    CFBundleGetMainBundle(), 
    CFSTR("beep"), 
    CFSTR("wav"), 
    NULL
);

// soundUrl logged:
// file://localhost/var/mobile/Applications/ ... beep.wav

AudioServicesCreateSystemSoundID(soundUrl, &beepOnSoundId);

// beepOnSoundId logged: 4097

AudioServicesPlaySystemSound(beepOnSoundId);

It stopped working, when I upgraded my device to iOS 5. I hear nothing. I logged out all the variables and none were nil or 0.

How has the API changed in iOS 5 that breaks my sound playing code?

Update

The problem may be because I have an AVCaptureSession running while I play the sound. iOS 5 somehow doesn't let you do this anymore. I need to play a beep sound while I am recording something from the camera.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This bug report could be related to your question, if you have an AVCaptureSession running.

Under iOS 5, when using an AudioServicesPlaySystemSound call, it will not work when there is an active AVCaptureSession with an audio device active.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...