How can I fade-out the sound played by MPMusicPlayerController?

人盡茶涼 提交于 2019-12-19 10:28:18

问题


I'd like to fade-out the sound played by MPMusicPlayerController over a particular time period? How can I do this?


回答1:


There is no fade functionality so you have to implement it yourself. Loop until volume is 0, and add a delay for each step. If you want all this to happen 2 seconds into the future, put the code on a block:

MPMusicPlayerController *iPod = [MPMusicPlayerController iPodMusicPlayer];

int64_t delay = 2LL * NSEC_PER_SEC;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,delay), dispatch_get_current_queue(), ^{
    while (iPod.volume>.1){
        iPod.volume -= .1;
        [NSThread sleepForTimeInterval:0.1];
    }
});


来源:https://stackoverflow.com/questions/6395375/how-can-i-fade-out-the-sound-played-by-mpmusicplayercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!