You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement MediaMetadataRetriever on top of MediaPlayer
also add MediaPlayer.getDuration() and MediaPlayer.getCurrentPosition()
This commit is contained in:
37
src/api-impl/android/media/MediaMetadataRetriever.java
Normal file
37
src/api-impl/android/media/MediaMetadataRetriever.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package android.media;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
public class MediaMetadataRetriever {
|
||||
|
||||
private MediaPlayer mediaPlayer;
|
||||
|
||||
public void release() {
|
||||
if (mediaPlayer != null)
|
||||
mediaPlayer.release();
|
||||
}
|
||||
|
||||
public void setDataSource(Context context, Uri uri) {
|
||||
mediaPlayer = new MediaPlayer();
|
||||
mediaPlayer.setDataSource(uri.getPath());
|
||||
}
|
||||
|
||||
public void setDataSource(String path) {
|
||||
mediaPlayer = new MediaPlayer();
|
||||
mediaPlayer.setDataSource(path);
|
||||
}
|
||||
|
||||
public byte[] getEmbeddedPicture() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String extractMetadata(int key) {
|
||||
switch (key) {
|
||||
case 9/*METADATA_KEY_DURATION*/:
|
||||
return String.valueOf(mediaPlayer.getDuration());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,8 +68,18 @@ public class MediaPlayer {
|
||||
|
||||
public void setVolume(float leftVolume, float rightVolume) {}
|
||||
|
||||
public int getDuration() {
|
||||
return native_getDuration(gtk_media_stream);
|
||||
}
|
||||
|
||||
public int getCurrentPosition() {
|
||||
return native_getCurrentPosition(gtk_media_stream);
|
||||
}
|
||||
|
||||
public static native void native_prepare(long gtk_media_stream);
|
||||
public native long native_setDataSource(String path);
|
||||
public static native void native_setOnCompletionListener(long gtk_media_stream, MediaPlayer.OnCompletionListener listener);
|
||||
public static native void native_start(long gtk_media_stream);
|
||||
public static native int native_getDuration(long gtk_media_stream);
|
||||
public static native int native_getCurrentPosition(long gtk_media_stream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user