magnusja / libaums

Open source library to access USB Mass Storage devices on Android without rooting your device
Apache License 2.0
1.27k stars 272 forks source link

Something wrong with HttpServer #359

Closed hugonnyy closed 1 year ago

hugonnyy commented 1 year ago

I use HttpServer to get U disk media , but it don't work and get exception: The code like this:

private HttpServer server = new AsyncHttpServer(8000);
.........
UsbFile file.......;
fileServer = new UsbFileHttpServer(file, server);
String path = fileServer.getBaseUrl() + "local" + name;
Log.d(TAG, "hostname: " + server.getHostname() + " ,baseUrl: " + fileServer.getBaseUrl() + " ,path: " + path);
mMediaPlayer.setDataSource(this, Uri.parse(path)); 
D/MainActivity: hostname:  ,baseUrl: http://:8000/ ,path: http://localhost:8000/aa阿杜 - Andy (Live).mp3
V/MediaPlayer: resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer: cleanDrmObj: mDrmObj=null mDrmSessionId=null
W/MediaPlayer: Couldn't open http://localhost:8000/...
    java.io.FileNotFoundException: No content provider: http://localhost:8000/aa阿杜 - Andy (Live).mp3
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1673)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1503)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1420)
        at android.media.MediaPlayer.attemptDataSource(MediaPlayer.java:1106)
        at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1078)
        at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1006)
        at com.yuanzp.mediaplayertest.MainActivity.play(MainActivity.java:210)
        at com.yuanzp.mediaplayertest.MainActivity$6.onClick(MainActivity.java:135)
        at android.view.View.performClick(View.java:7140)
        at android.view.View.performClickInternal(View.java:7117)
        at android.view.View.access$3500(View.java:801)
        at android.view.View$PerformClick.run(View.java:27351)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7386)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1072)

would you please give me some suggestions? thank you. by the way , my code is write by java.

magnusja commented 1 year ago

You are using the wrong method. Use this one https://developer.android.com/reference/kotlin/android/media/MediaPlayer#setdatasource_3