2013-07-05 2 views
1

iOS의 오디오 대기열 서비스를 사용하여 AAC (kAudioFormatMPEG4AAC) 파일을 재생하고 있습니다. 그것은 정상적으로 작동하므로 내 코드가 작동합니다.AudioDataPacketCount가 ValueUnknown을 반환합니다.

이제 탐색 기능을 찾고 있습니다. 이를 위해서는 총 오디오 패킷 수가 필요합니다. 내 재산 청취자 시저가 kAudioFileStreamProperty_ReadyToProducePackets을 받으면 내가 할 :

UInt64 totalPackets; 
UInt32 size = sizeof(totalPackets); 
OSStatus status; 

status = AudioFileStreamGetProperty(inAudioFileStream, 
            kAudioFileStreamProperty_AudioDataPacketCount, 
            &packetCountSize, 
            &myData->totalPackets); 

문제는 AudioFileStreamGetProperty() 반환 kAudioFileStreamError_ValueUnknown (1970170687 디버거에서 인쇄 할 때)이다.

내가 잘못 했나요?

답변

2

나는 전혀 잘못 안하고있는 것으로 나타났습니다.

iOS API는이 파일 형식에 각각 자체 패킷 수가있는 조각을 포함 할 수 있기 때문에이 기능을 제공하지 않는 것으로 나타났습니다. 따라서 파일의 총 패킷 수는 첫 번째 헤더를 읽은 후 알 수 없습니다.

그러나 많은 오디오 파일에는 조각이 하나뿐이므로 iOS가 특정 시점 (즉 파일 헤더를 읽은 후)에 알고있는 패킷 수를 제공하지 않는다는 것이 약간 슬픈 일입니다. AudioFileStreamSeek() 작업 할 때

나는 아이폰 OS에서 정보를 집어 넣은 다음 생각 :

- (SInt64)getTotalPacketCount 
{ 
    OSStatus status; 
    UInt32 ioFlags = 0; 
    long long byteOffset = 0; 
    SInt64 lower  = 0; 
    SInt64 upper  = 1000000; // Large enough to fit any packet count. 
    SInt64 current;    // Current packet count. 

    // Binary search to highest packet count that has successful seek. 
    while (upper - lower > 1 || status != 0) 
    { 
     current = (upper + lower)/2; 
     status = AudioFileStreamSeek(audioFileStream, current, &byteOffset, &ioFlags); 

     if (status == 0) 
     { 
      lower = current; 
     } 
     else 
     { 
      upper = current; 
     } 
    } 

    return current + 1; // Go from packet number to count. 
}