gpt4 book ai didi

iOS:在特定时间播放音频文件并在特定持续时间后停止

转载 作者:行者123 更新时间:2023-11-29 04:22:48 25 4
gpt4 key购买 nike

我的应用程序有一个长度为 500 微秒的音频文件。我希望应用程序用户以微秒 100 播放音频(通过按下按钮),并且音频将在微秒 150 处自动停止。这是我迄今为止所做的代码:

    AVAudioPlayer *audioPlayer = [[[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:filePath]
error:nil] autorelease];
[audioPlayer setCurrentTime:100.00f];
[audioPlayer play];

你能帮我完成停止部分吗?谢谢

最佳答案

您可以创建一个具有所需播放间隔的 NSTimer 实例,然后在计时器触发时停止音频。在主线程上以及代码中适用区域的某个位置创建计时器,您可以在其中获取audioPlayer 的引用。确保你处理中断,IE,用户以某种方式暂停或停止音频,或者如果audioPlayer在某个地方被释放,你的应用程序进入后台,或者任何你需要处理的事情,通过无效和处置计时器。有关 NSTimer 的信息,请参阅文档。 http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nstimer_Class/Reference/NSTimer.html

关于iOS:在特定时间播放音频文件并在特定持续时间后停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12752405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com