gpt4 book ai didi

ios - CocosDenshion : why isPlaying always false (I can hear the music)?

转载 作者:行者123 更新时间:2023-11-29 04:06:21 26 4
gpt4 key购买 nike

我有这个:

-(ALuint)ID
{ return self.soundSource->_sourceId; }

-(void)play
{
[self.engine playSound:self.soundSource.soundId
sourceGroupId:0
pitch:self.pitch
pan:1.0
gain:1.0
loop:NO];
}

-(NSTimeInterval)duration
{ return durationOfSourceId(self.ID); }

-(NSTimeInterval)offset
{ return elapsedTimeOfSourceId(self.ID); }

-(BOOL)isPlaying
{
NSTimeInterval secondsRemaining = self.duration - self.offset;
NSLog(@"<%.3f>", self.soundSource.durationInSeconds);
NSLog(@"<%.3f> - <%.3f> = <%.3f> isPlaying <%i>", self.duration, self.offset, secondsRemaining, self.soundSource.isPlaying);
return (secondsRemaining > 0.0);
}


#pragma mark - OpenAL addons

static NSTimeInterval elapsedTimeOfSourceId(ALuint sourceID)
{
float result = 0.0;
alGetSourcef(sourceID, AL_SEC_OFFSET, &result);
return result;
}

static NSTimeInterval durationOfSourceId(ALuint sourceID)
{
//Thanks to http://stackoverflow.com/a/8822347

ALint bufferID, bufferSize, frequency, bitsPerSample, channels;
alGetSourcei(sourceID, AL_BUFFER, &bufferID);
alGetBufferi(bufferID, AL_SIZE, &bufferSize);
alGetBufferi(bufferID, AL_FREQUENCY, &frequency);
alGetBufferi(bufferID, AL_CHANNELS, &channels);
alGetBufferi(bufferID, AL_BITS, &bitsPerSample);
NSTimeInterval result = ((double)bufferSize)/(frequency*channels*(bitsPerSample/8));
return result;
}

其中引擎只是 CDSoundEngine 的一个实例。我真的很想知道音乐什么时候停止。我已经沉浸了一整天了,我累了。

它记录:[1445:707] <1.656>[1445:707] <1.656> - <0.000> = <1.656> 正在播放 <0>

所以 OpenAL 源 ID 是正确的(因为我可以获得持续时间)。CDSoundSource 也是正确的(因为我也可以从中获取持续时间)。我可以听到正在播放的声音。

但是 AL_SEC_OFFSET 始终为 0.0,isPlaying 始终为 NO。

最佳答案

为什么不获取源的状态并检查它是否真的正在播放?:

alGetSourcei(source, AL_SOURCE_STATE, &state);

return (state == AL_PLAYING);

关于ios - CocosDenshion : why isPlaying always false (I can hear the music)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15140570/

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