-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is analogous to what we do for text/subtitles, and adds support for playlists where the type of metadata changes from one playlist item to the next. Issue: #2176 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=143948307
- Loading branch information
Showing
4 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
library/src/main/java/com/google/android/exoplayer2/metadata/MetadataDecoderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2017 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.android.exoplayer2.metadata; | ||
|
||
import com.google.android.exoplayer2.Format; | ||
import com.google.android.exoplayer2.metadata.emsg.EventMessageDecoder; | ||
import com.google.android.exoplayer2.metadata.id3.Id3Decoder; | ||
import com.google.android.exoplayer2.metadata.scte35.SpliceInfoDecoder; | ||
import com.google.android.exoplayer2.util.MimeTypes; | ||
|
||
/** | ||
* A factory for {@link MetadataDecoder} instances. | ||
*/ | ||
public interface MetadataDecoderFactory { | ||
|
||
/** | ||
* Returns whether the factory is able to instantiate a {@link MetadataDecoder} for the given | ||
* {@link Format}. | ||
* | ||
* @param format The {@link Format}. | ||
* @return Whether the factory can instantiate a suitable {@link MetadataDecoder}. | ||
*/ | ||
boolean supportsFormat(Format format); | ||
|
||
/** | ||
* Creates a {@link MetadataDecoder} for the given {@link Format}. | ||
* | ||
* @param format The {@link Format}. | ||
* @return A new {@link MetadataDecoder}. | ||
* @throws IllegalArgumentException If the {@link Format} is not supported. | ||
*/ | ||
MetadataDecoder createDecoder(Format format); | ||
|
||
/** | ||
* Default {@link MetadataDecoder} implementation. | ||
* <p> | ||
* The formats supported by this factory are: | ||
* <ul> | ||
* <li>ID3 ({@link Id3Decoder})</li> | ||
* <li>EMSG ({@link EventMessageDecoder})</li> | ||
* <li>SCTE-35 ({@link SpliceInfoDecoder})</li> | ||
* </ul> | ||
*/ | ||
MetadataDecoderFactory DEFAULT = new MetadataDecoderFactory() { | ||
|
||
@Override | ||
public boolean supportsFormat(Format format) { | ||
return getDecoderClass(format.sampleMimeType) != null; | ||
} | ||
|
||
@Override | ||
public MetadataDecoder createDecoder(Format format) { | ||
try { | ||
Class<?> clazz = getDecoderClass(format.sampleMimeType); | ||
if (clazz == null) { | ||
throw new IllegalArgumentException("Attempted to create decoder for unsupported format"); | ||
} | ||
return clazz.asSubclass(MetadataDecoder.class).getConstructor().newInstance(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException("Unexpected error instantiating decoder", e); | ||
} | ||
} | ||
|
||
private Class<?> getDecoderClass(String mimeType) { | ||
if (mimeType == null) { | ||
return null; | ||
} | ||
try { | ||
switch (mimeType) { | ||
case MimeTypes.APPLICATION_ID3: | ||
return Class.forName("com.google.android.exoplayer2.metadata.id3.Id3Decoder"); | ||
case MimeTypes.APPLICATION_EMSG: | ||
return Class.forName("com.google.android.exoplayer2.metadata.emsg.EventMessageDecoder"); | ||
case MimeTypes.APPLICATION_SCTE35: | ||
return Class.forName("com.google.android.exoplayer2.metadata.scte35.SpliceInfoDecoder"); | ||
default: | ||
return null; | ||
} | ||
} catch (ClassNotFoundException e) { | ||
return null; | ||
} | ||
} | ||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters