I was trying to create a simply MediaPlayer but when playing .opus files it is not working. I tested it with an mp3 and it worked (but does not renaming the opus to mp3, for example). I've read something about .mkv (Matroska Container Format) but I don't know what exactly is it and if it could help me.
In my code I've something like this:
var player : MediaPlayer = MediaPlayer()
var uri : Uri = Uri.parse(selectedFile.absolutePath)
try {
player.setDataSource(selectedFile.absolutePath)
player = MediaPlayer.create(this, uri)
player.prepare()
player.start()
}catch (e : Exception){
Toast.makeText(this, "Error reading file", Toast.LENGTH_SHORT).show()
}
And I got different errors trying to solve it, but this is the one I have now (exactly in the MediaPlayer.create line):
03-07 02:00:24.393 32251-32251/com.package.app E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present 03-07 02:00:24.393 32251-32251/com.package.app D/MediaPlayer: Couldn't open file on client side, trying server side 03-07 02:00:24.413 32251-32274/com.package.app E/MediaPlayer: error (1, -2147483648) 03-07 02:00:24.413 32251-32251/com.package.app D/MediaPlayer: create failed: java.io.IOException: Prepare failed.: status=0x1 at android.media.MediaPlayer._prepare(Native Method) at android.media.MediaPlayer.prepare(MediaPlayer.java:1157) at android.media.MediaPlayer.create(MediaPlayer.java:890) at android.media.MediaPlayer.create(MediaPlayer.java:863) at android.media.MediaPlayer.create(MediaPlayer.java:842) at com.package.app.MainActivity.initializePlayer(MainActivity.kt:167) at com.package.app.MainActivity$onCreate$1.onClick(MainActivity.kt:111) at android.view.View.performClick(View.java:4791) at android.view.View$PerformClick.run(View.java:19903) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5304) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) 03-07 02:00:24.433 32251-32251/com.package.app E/MediaPlayer: Attempt to call getDuration without a valid mediaplayer error (-38, 0) 03-07 02:00:24.433 32251-32251/com.package.app I/ViewRootImpl: CPU Rendering VSync enable = true 03-07 02:00:24.443 32251-32251/com.package.app E/MediaPlayer: Error (-38,0)