簡體   English   中英

從 DropBox 設置數據源時 MediaPlayer 音頻不播放

[英]MediaPlayer audio not playing when setting data source from DropBox

我正在為一個項目制作音樂播放器 Android 應用程序,我想要 stream 我在 DropBox 上上傳的音樂(我嘗試使用 Google 雲端硬盤,但顯然自 2016 年以來托管服務已被棄用?)。 我在日志中看不到任何錯誤,但沒有播放音樂。 當我嘗試播放 R.raw 文件夾中的音樂時,一切正常。 我是 Android Studio 的新手,我不明白這里的問題。

MediaPlayer mp = new MediaPlayer();
    try{
        mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mp.setDataSource("https://www.dropbox.com/s/57x8706nls1pliu/toto.mp3");
        mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.start();
                Toast.makeText(getApplicationContext(), "Music playing!", Toast.LENGTH_LONG).show();
            }
        });
        mp.prepareAsync();
    } catch(IOException e){
        e.printStackTrace();
    }

當我運行該應用程序時,我的日志如下所示:

2022-04-10 12:56:07.056 20298-20298/? I/ample.musicspo: Late-enabling -Xcheck:jni
2022-04-10 12:56:07.107 20298-20298/? I/ample.musicspo: Unquickening 12 vdex files!
2022-04-10 12:56:07.110 20298-20298/? W/ample.musicspo: Unexpected CPU variant for X86 using defaults: x86
2022-04-10 12:56:07.853 20298-20298/com.example.musicspot D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2022-04-10 12:56:07.854 20298-20298/com.example.musicspot D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2022-04-10 12:56:07.938 20298-20373/com.example.musicspot D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2022-04-10 12:56:07.946 20298-20373/com.example.musicspot D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2022-04-10 12:56:07.956 20298-20373/com.example.musicspot D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2022-04-10 12:56:08.304 20298-20298/com.example.musicspot W/ample.musicspo: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-04-10 12:56:08.306 20298-20298/com.example.musicspot W/ample.musicspo: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-04-10 12:56:08.540 20298-20298/com.example.musicspot W/MediaPlayer: Use of stream types is deprecated for operations other than volume control
2022-04-10 12:56:08.540 20298-20298/com.example.musicspot W/MediaPlayer: See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2022-04-10 12:56:08.551 20298-20298/com.example.musicspot V/MediaHTTPService: MediaHTTPService(android.media.MediaHTTPService@e0d91e9): Cookies: null
2022-04-10 12:56:08.700 20298-20369/com.example.musicspot D/HostConnection: HostConnection::get() New Host Connection established 0xf3ab5610, tid 20369
2022-04-10 12:56:08.764 20298-20369/com.example.musicspot D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2022-04-10 12:56:08.770 20298-20369/com.example.musicspot W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2022-04-10 12:56:08.772 20298-20369/com.example.musicspot D/EGL_emulation: eglCreateContext: 0xf3ab4f80: maj 3 min 0 rcv 3
2022-04-10 12:56:08.774 20298-20369/com.example.musicspot D/EGL_emulation: eglMakeCurrent: 0xf3ab4f80: ver 3 0 (tinfo 0xf3df9ff0) (first time)
2022-04-10 12:56:08.795 20298-20369/com.example.musicspot I/Gralloc4: mapper 4.x is not supported
2022-04-10 12:56:08.797 20298-20369/com.example.musicspot D/HostConnection: createUnique: call
2022-04-10 12:56:08.797 20298-20369/com.example.musicspot D/HostConnection: HostConnection::get() New Host Connection established 0xf3ab5060, tid 20369
2022-04-10 12:56:08.798 20298-20369/com.example.musicspot D/goldfish-address-space: allocate: Ask for block of size 0x100
2022-04-10 12:56:08.850 20298-20369/com.example.musicspot D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3f3ffe000 size 0x2000
2022-04-10 12:56:08.873 20298-20369/com.example.musicspot D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2022-04-10 12:56:09.131 20298-20334/com.example.musicspot W/MediaPlayer-JNI: MediaPlayer finalized without being released

我做錯了什么嗎? 當我在線粘貼時,我在數據源中使用的鏈接有效。

您在代碼中使用的鏈接指向文件的 HTML 預覽頁面,而不是文件內容本身。 嘗試修改此處記錄的鏈接以直接訪問文件數據:

https://help.dropbox.com/files-folders/share/force-download

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM