0

まず、私はObjective Cでかなり新しいです。特定の条件下で音を鳴らして振動させたいと思っています。私の iPhone 4 はミュートになっていません。大文字と小文字の区別を確認し、AVAudioPlay と SystemSound の両方を使用してファイルを再生しようとしましたが、バイブレーションも機能しません。AudioToobox と AVfoundation は .h にインポートされます。オーディオは、iOS シミュレーターで両方の方法で再生されます。

SystemSound を使用したコードは次のとおりです。

if (al == 1){
CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Alarm", CFSTR ("wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
        AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);}

And with AVAudioPlayer:

if (al == 1) {NSString *path = [[NSBundle mainBundle] pathForResource:@"alarmtwo" ofType:@"wav"];
        AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];        
        theAudio.numberOfLoops = 0;
        theAudio.volume = 1.5;
        [theAudio prepareToPlay];
        [theAudio play];}

By the way, the variable al sets to 0 after it plays. Is my coding wrong to have the sound and vibrate work on the device itself? Is there a specific type of .wav file that needs to be played? Any help would be appreciated.

4

1 に答える 1

2

私はこの同じ問題に遭遇していました。実際には、通常の音量が上がっていても、少なくとも私の場合はミュートに設定されていたアラート専用の 2 つ目の音量設定があります。デバイスの設定アプリのサウンドメニューの下を見て、それを上げてください。

サウンドが実際に再生されることが重要な場合は、実際にリリースされたアプリにアラートを使用したくないでしょう。ユーザーは、この別のオーディオ設定がオンになっていることを確認する必要があるからです。

于 2011-10-15T18:06:46.140 に答える