0

私はこれを持っています:

-(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;
}

engine は CDSoundEngine の単なるインスタンスです。いつ音楽が止まるか知りたいです。私は今、一日中それに夢中で、疲れています。

ログ: [1445:707] <1.656> [1445:707] <1.656> - <0.000> = <1.656> isPlaying <0>

したがって、OpenAL ソース ID は正しいです (期間を取得できるため)。CDSoundSource も正しいです (そこから持続時間も取得できるため)。再生音が聞こえます。

ただし、AL_SEC_OFFSET は常に 0.0 で、isPlaying は常に NO です。

4

1 に答える 1

1

ソースの状態を取得して、実際に再生されているかどうかを確認してみませんか?:

alGetSourcei(source, AL_SOURCE_STATE, &state);

return (state == AL_PLAYING);
于 2013-02-28T16:54:39.093 に答える