mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Avoid throwing an exception when an ID3 header is not found
Issue:#1966 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=136836332
This commit is contained in:
parent
eeb37d73e7
commit
6e69b98517
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.extractor.ts;
|
package com.google.android.exoplayer2.extractor.ts;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorOutput;
|
import com.google.android.exoplayer2.extractor.ExtractorOutput;
|
||||||
@ -28,6 +29,8 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
|
|||||||
*/
|
*/
|
||||||
/* package */ final class Id3Reader implements ElementaryStreamReader {
|
/* package */ final class Id3Reader implements ElementaryStreamReader {
|
||||||
|
|
||||||
|
private static final String TAG = "Id3Reader";
|
||||||
|
|
||||||
private static final int ID3_HEADER_SIZE = 10;
|
private static final int ID3_HEADER_SIZE = 10;
|
||||||
|
|
||||||
private final ParsableByteArray id3Header;
|
private final ParsableByteArray id3Header;
|
||||||
@ -82,7 +85,14 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
|
|||||||
headerBytesAvailable);
|
headerBytesAvailable);
|
||||||
if (sampleBytesRead + headerBytesAvailable == ID3_HEADER_SIZE) {
|
if (sampleBytesRead + headerBytesAvailable == ID3_HEADER_SIZE) {
|
||||||
// We've finished reading the ID3 header. Extract the sample size.
|
// We've finished reading the ID3 header. Extract the sample size.
|
||||||
id3Header.setPosition(6); // 'ID3' (3) + version (2) + flags (1)
|
id3Header.setPosition(0);
|
||||||
|
if ('I' != id3Header.readUnsignedByte() || 'D' != id3Header.readUnsignedByte()
|
||||||
|
|| '3' != id3Header.readUnsignedByte()) {
|
||||||
|
Log.w(TAG, "Discarding invalid ID3 tag");
|
||||||
|
writingSample = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
id3Header.skipBytes(3); // version (2) + flags (1)
|
||||||
sampleSize = ID3_HEADER_SIZE + id3Header.readSynchSafeInt();
|
sampleSize = ID3_HEADER_SIZE + id3Header.readSynchSafeInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user