tags:

views:

94

answers:

2

as topic... is it possible ?

Thanks

again, I have attached the code as follows, please check which step is wrong .thanks.

    //@step
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory =   kAudioSessionCategory_MediaPlayback;
OSStatus error = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,                                            sizeof(sessionCategory),&sessionCategory);

if (error) 
    printf("ERROR AudioSessionSetProperty ! %d\n", error);

//@step 
NSString* filePath = @"AlarmClockBell.caf";
[Util restoreResourceFile:filePath];
filePath =[Util getFileFullPathFromSysDoc:filePath];
NSURL *soundFileURL = [NSURL fileURLWithPath:filePath];   
NSError* error ;
AVAudioPlayer * audioPalyer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: &error];
if (nil == audioPalyer) 
{
    AppTrace3(self, @"Faild to play", soundFileURL, error);
    return FALSE;
}
[audioPalyer prepareToPlay];
[audioPalyer setVolume: 5 ];
[audioPalyer setDelegate: self];
 audioPalyer.numberOfLoops = 10;

[audioPalyer play];

thanks...

A: 

It must be, there's been a couple games I've had which (even when its in mute mode) will play sound. Unfortunately this was discovered whilst attempting to play games covertly in class.

As to how to actually do it, I really don't have any idea.

Paul
Hi, paul, thanks for your answer, does the game is from AppStore ? I have find some solution but it seem is only works on unlock iPhone ...
Robin
+1  A: 

If you look in the docs under Audio Session Categories, you'll find a number of modes that you can set to tell the system how your app plans to use audio. The default is AVAudioSessionCategorySoloAmbient which tracks the ring/silent switch and the screen lock.

To have your app ignore the ring/silent switch settings, you could try changing the category:

#import <AudioToolbox/AudioToolbox.h>

AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, 
                         sizeof(sessionCategory),&sessionCategory);

If you want to allow iPod audio to continue playing in the background, you'll also want to check kAudioSessionProperty_OverrideCategoryMixWithOthers.

Ramin
Hi, Ramin, thanks you very much for the answer, that is very helpful, but I try to do the way, it still no works fine ... the volume of the iPhone device is mute (volume adjust to zero) , when the code running , it still no sound unless I adjust the volume by manual ...my code as follows:
Robin
sorry for this is very hard to read ....:{
Robin
hi, Ramin, I have add code in the question above, please help me check it if you have time... thanks!
Robin
Setting the audio category only ignores the 'mute' toggle switch or if the screen has been put to sleep, not the master volume level (the +/- volume rocker).There are a couple of ways to adjust the master volume via software, but most use undocumented APIs and may well get your app rejected. Here's one method: http://blog.stormyprods.com/2009/06/adjusting-iphone-master-volume.html
Ramin