IOS 播放聲音和震動

使用AudioServicesPlaySystemSound 這個接口來進行聲音和震動的播放, 當然需要在工程中加入AudioToolBox.framework

1. 播放震動     

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

2. 播放特定的聲音

static SystemSoundID soundIDTest = 0;

NSString * path = [[NSBundle mainBundlepathForResource:@"test" ofType:@"wav"];

if (path) {

      AudioServicesCreateSystemSoundID( (CFURLRef)[NSURL fileURLWithPath:path], &soundIDTest );

}

    AudioServicesPlaySystemSoundsoundIDTest );

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章