1

I am making a Music Player Android application for a project and I want to stream music that I have uploaded on DropBox (I tried using Google Drive but apparently the hosting service got deprecated since 2016?). I can't see any errors in my logs but the music isn't playing. When I try to play music from my R.raw folder, it works perfectly alright. I am fairly new to Android Studio and I don't understand the issue here.

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();
    }

When I run the app my logs look like this:

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

Is there anything I am doing wrong? The link that I have used in the data source works when I paste it online.

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

The link you're using in your code points to an HTML preview page for the file, not the file contents itself. Try modifying the link as documented here for direct file data access:

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

Greg
  • 16,359
  • 2
  • 34
  • 44