0

私は次のコードを書きました:

-(void)runTimer
{
    myTicker=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
    myTicker = [NSTimer scheduledTimerWithTimeInterval:60.00 target:self selector:@selector(vibrate) userInfo:nil repeats:YES];
}

-(void)showActivity
{
    NSDateFormatter *formatter =
                  [[[NSDateFormatter alloc] init] autorelease];
            NSDate *date = [NSDate date];
        [formatter setTimeStyle:NSDateFormatterMediumStyle];
         [timerLabel setText:[formatter stringFromDate:date]];
}
-(void) vibrate{
AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);

}

iPhoneを振動させるのではなく、オーディオファイルを再生したい。それは可能ですか?

4

5 に答える 5

1

主な質問に正接しますが、タイマーセレクターによって呼び出されるメソッドは次の形式である必要があります...

-(void) aribtaryMethodName:(NSTimer *) theTimer;

...または正しく呼び出されない場合があります。セレクターは次のようになります。

myTicker=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(aribtaryMethodName:) userInfo:nil repeats:YES];
于 2010-02-01T12:57:06.457 に答える
0
-(IBAction)slider1Changed:(id)sender
{
    [timer invalidate];
    float sliderValue=slider1.value;
    int totalSecond=(int)sliderValue;
    time=totalSecond;
    int sec= totalSecond %60;
    int min= (totalSecond -sec)/60;
    sliderValue=(float)totalSecond;
    runTime.text=[NSString stringWithFormat:@"%d:%.2d",min,sec];
    [slider1 setValue:sliderValue];
    timer =   [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerChanged) userInfo:nil repeats:YES];

    // to play the audio from particular time duration
    [player setCurrentTime:totalSecond];
}

-(void)timerChanged
{
   int totalSecond=[player duration];

   float slider1Time=(float)time;
   if (time <= totalSecond) {
      int sec= time %60;
      int min= (time -sec)/60;
      runTime.text=[NSString stringWithFormat:@"%d:%.2d",min,sec];
      [slider1 setValue:slider1Time];
   }
   else
   {
      [player stop];
      [timer invalidate];
   }
   time +=1;

}
于 2013-03-23T17:00:55.750 に答える
0

Apple のサンプル プロジェクトBubbleLevelを確認してください。プロジェクトに SoundEffect.h と SoundEffect.m を追加してから、次のように呼び出します。

mySound = [[SoundEffect alloc]
    initWithContentsOfFile:[mainBundle pathForResource:@"mySound"
    ofType:@"aif"]];
[mySound play];    

警告: iTunes 経由で変換された AIF サウンドしか再生できませんでした。CAFファイルを含め、他のすべてが失敗しました。要するに、どんなサウンドでも iTunes にインポート (ドラッグ アンド ドロップ) し、エクスポートを AIF 形式に変更してから、ファイルをエクスポートします。

于 2010-02-02T08:10:23.987 に答える
0

はい。ファイルがあると仮定すると.caf、それを再生できます

SystemSoundID sound_id;
AudioServicesCreateSystemSoundID(NSURL_of_your_caf_file, &sound_id);
...
AudioServicesPlaySystemSound(sound_id);

音楽を再生するには、AVAudioPlayer代わりに使用することをお勧めします。

于 2010-02-01T12:17:08.500 に答える
0

もちろん。AVAudioPlayer クラスを参照してください。

于 2010-02-01T12:18:02.653 に答える