2013-02-28 6 views
0

나는이있다 :CocosDenshion : 왜 isPlaying이 항상 거짓입니까? (음악을들을 수 있습니까?)

엔진이 CDSoundEngine 단지 인스턴스
-(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; 
} 

. 음악이 언제 중단되는지 정말 알고 싶습니다. 나는 하루 종일 그것에 빠져있다. 그리고 나는 피곤하다.

이 기록 : [1445 : 707] < 1.656> [1,445을 : 707] < 1.656> - < 0.000> = < 1.656> isPlaying 0>

그래서 OpenAL에 소스 ID 옳은 < (보낸 나는 기간을 얻을 수있다). CDSoundSource 또한 맞습니다 (이후부터 그 기간을 얻을 수 있기 때문에). 소리가 들리는 것을들을 수 있습니다.

하지만 AL_SEC_OFFSET은 항상 0.0이며 isPlaying은 항상 NO입니다.

답변

1

이유가 정말 연주되는 경우, 원본의 상태를 얻을 확인?

alGetSourcei(source, AL_SOURCE_STATE, &state); 

return (state == AL_PLAYING); 
+0

감사합니다, 난 그냥 노력하겠습니다니까. – Geri

+0

실제로 내가 OpenAL로 직접 플레이한다면 위의 모든 접근법이 잘 작동합니다. – Geri

+0

CDAudioEngine 또는 SimpleAudioEngine으로 CDSoundSource를 재생하면 콜백이 호출되지 않습니다. – Geri