gpt4 book ai didi

ios - AVMutableAudioMixInputParameters setVolume atTime 仅适用于 kCMTimeZero

转载 作者:行者123 更新时间:2023-11-29 13:14:19 25 4
gpt4 key购买 nike

我正在使用 Xcode 开发一个 iOS 应用程序。我还是编程新手。我试图在使用 AVPlayer 播放时设置音轨的音量。如果将时间设置为 kCMTimeZero 效果很好,但我希望它在按下按钮一秒后设置音量。

工作

- (IBAction)maxVolButtonPressed:(id)sender {
[audioInputParams1 setVolume:1 atTime:time1];
[self applyAudioMix];
}

工作

- (IBAction)minVolButtonPressed:(id)sender {
[audioInputParams1 setVolume:0 atTime:kCMTimeZero];
[self applyAudioMix];
}

atTime后要延迟一秒应该怎么写?

回答:好的,所以我想通了。您必须添加当前项目所在的时间。我使用时间间隔非常短的 setVolumeRampFromStartVolume 而不是 setVolume。由于某种原因,setVolume 逐渐淡化到给定的音量,我还没有弄明白为什么。它像这样对我有用:

CMTime time1 = CMTimeMake(1000, 1000); //2s
CMTime time2 = CMTimeMake(1001, 1000); //3s
CMTime timeCurrent = [player currentTime];
CMTime time1Added = CMTimeAdd(timeCurrent, time1);
CMTime time2Added = CMTimeAdd(timeCurrent, time2);
CMTimeRange fadeInTimeRange = CMTimeRangeFromTimeToTime(time1Added, time2Added);
[audioInputParams1 setVolumeRampFromStartVolume:0 toEndVolume:1 timeRange:fadeInTimeRange];
[self applyAudioMix];

最佳答案

你应该这样做:

- (IBAction)maxVolButtonPressed:(id)sender {
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(setVolume:) userInfo:nil repeats:NO];
}

- (void)setVolume:(id)sender{
[audioInputParams1 setVolume:1 atTime:kCMTimeZero];
[self applyAudioMix];
}

在第一种方法中,您说:WAITING 1 秒,然后调用方法 setVolume:。

关于ios - AVMutableAudioMixInputParameters setVolume atTime 仅适用于 kCMTimeZero,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16217715/

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