forked from google/ExoPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vorbis comments support to flac extractor
Decode and add vorbis comments from the flac file to metadata. google#5527
- Loading branch information
Showing
9 changed files
with
394 additions
and
1 deletion.
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
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
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
59 changes: 59 additions & 0 deletions
59
...ore/src/main/java/com/google/android/exoplayer2/metadata/vorbis/VorbisCommentDecoder.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,59 @@ | ||
/* | ||
* Copyright (C) 2019 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.vorbis; | ||
|
||
import androidx.annotation.Nullable; | ||
import com.google.android.exoplayer2.metadata.Metadata; | ||
import java.util.ArrayList; | ||
|
||
/** Decodes vorbis comments */ | ||
public class VorbisCommentDecoder { | ||
|
||
private static final String SEPARATOR = "="; | ||
|
||
/** | ||
* Decodes an {@link ArrayList} of vorbis comments. | ||
* | ||
* @param metadataStringList An {@link ArrayList} containing vorbis comments as {@link String} | ||
* @return A {@link Metadata} structure with the vorbis comments as its entries. | ||
*/ | ||
public Metadata decodeVorbisComments(@Nullable ArrayList<String> metadataStringList) { | ||
if (metadataStringList == null || metadataStringList.size() == 0) { | ||
return null; | ||
} | ||
|
||
ArrayList<VorbisCommentFrame> vorbisCommentFrames = new ArrayList<>(); | ||
VorbisCommentFrame vorbisCommentFrame; | ||
|
||
for (String commentEntry : metadataStringList) { | ||
String[] keyValue; | ||
|
||
keyValue = commentEntry.split(SEPARATOR); | ||
if (keyValue.length != 2) { | ||
/* Could not parse this comment, no key value pair found */ | ||
continue; | ||
} | ||
vorbisCommentFrame = new VorbisCommentFrame(keyValue[0], keyValue[1]); | ||
vorbisCommentFrames.add(vorbisCommentFrame); | ||
} | ||
|
||
if (vorbisCommentFrames.size() > 0) { | ||
return new Metadata(vorbisCommentFrames); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
.../core/src/main/java/com/google/android/exoplayer2/metadata/vorbis/VorbisCommentFrame.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,102 @@ | ||
/* | ||
* Copyright (C) 2019 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.vorbis; | ||
|
||
import static com.google.android.exoplayer2.util.Util.castNonNull; | ||
|
||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import androidx.annotation.Nullable; | ||
import com.google.android.exoplayer2.metadata.Metadata; | ||
|
||
/** Base class for Vorbis Comment Frames. */ | ||
public class VorbisCommentFrame implements Metadata.Entry { | ||
|
||
/** The frame key and value */ | ||
public final String key; | ||
|
||
public final String value; | ||
|
||
/** | ||
* @param key The key | ||
* @param value Value corresponding to the key | ||
*/ | ||
public VorbisCommentFrame(String key, String value) { | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
/* package */ VorbisCommentFrame(Parcel in) { | ||
this.key = castNonNull(in.readString()); | ||
this.value = castNonNull(in.readString()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return key; | ||
} | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
// Parcelable implementation. | ||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
dest.writeString(key); | ||
dest.writeString(value); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object obj) { | ||
if ((obj != null) && (obj.getClass() == this.getClass())) { | ||
if (this == obj) { | ||
return true; | ||
} else { | ||
VorbisCommentFrame compareFrame = (VorbisCommentFrame) obj; | ||
if (this.key.equals(compareFrame.key) && this.value.equals(compareFrame.value)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = 17; | ||
|
||
result = 31 * result + key.hashCode(); | ||
result = 31 * result + value.hashCode(); | ||
|
||
return result; | ||
} | ||
|
||
public static final Parcelable.Creator<VorbisCommentFrame> CREATOR = | ||
new Parcelable.Creator<VorbisCommentFrame>() { | ||
|
||
@Override | ||
public VorbisCommentFrame createFromParcel(Parcel in) { | ||
return new VorbisCommentFrame(in); | ||
} | ||
|
||
@Override | ||
public VorbisCommentFrame[] newArray(int size) { | ||
return new VorbisCommentFrame[size]; | ||
} | ||
}; | ||
} |
Oops, something went wrong.