小编yon*_*obi的帖子

Objective c avaudioplayer不播放声音

我正在使用此功能在我的iPhone应用程序上播放声音.问题是声音没有播放.该功能正常工作并正确读取文件路径,我没有收到任何错误,但声音没有播放

-(void) playSound : (NSString *) fName; {
    if ([audioPlayer isPlaying]) {
        [audioPlayer stop];
    }
    audioPlayer.volume = 1.0;
    soundpath = [NSString stringWithFormat:@"sounds/%@", fName];
    soundFilePath = [[NSBundle mainBundle] pathForResource:soundpath  ofType: @"mp3"];
    soundURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
    audioPlayer.numberOfLoops = -1;
    if (audioPlayer == nil){

    }
else {
    [audioPlayer play];
        if ([audioPlayer isPlaying]) {
            NSLog(@"%@", @"run");
     }
}
}
Run Code Online (Sandbox Code Playgroud)

objective-c avaudioplayer

4
推荐指数
1
解决办法
968
查看次数

如何设置iPhone振动时长?

我正在使用 AudioServicesPlaySystemSound 来调用振动函数:

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)

有什么办法可以设置振动的持续时间吗?我知道默认持续时间是 0.4 秒,但有时我想让设备振动的时间比这个短或长。

iphone iphone-vibrate

2
推荐指数
1
解决办法
4781
查看次数