I'm trying to devlop my own application to play live internet radio on my phone and make it compatible with android auto. So, I started a new project Android auto on last version of Androit Studio (2022.3.1).
I don't have an MP3 file, just a working URI that I use in a browser : http://streamingp.shoutcast.com/NostalgiePremium-mp3
Here is my java code, the stream should start playing when I run the application (then i will add a "play" and "Stop" button)
package com.example.mediaservicesample;
import androidx.appcompat.app.AppCompatActivity;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Bundle;
import android.media.MediaPlayer;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri myUri = Uri.parse("http://streamingp.shoutcast.com/NostalgiePremium-mp3");
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioAttributes(
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.build()
);
try {
mediaPlayer.setDataSource(getApplicationContext(), myUri);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
mediaPlayer.prepare();
} catch (IOException e) {
throw new RuntimeException(e);
}
mediaPlayer.start();
}
}
I tried this code, the application open on my phone but I have no music.
I'm getting these console logs as shown below
---------------------------- PROCESS STARTED (15249) for package com.example.webradio ----------------------------
2023-08-18 13:45:49.748 15249-15249 nativeloader com.example.webradio D Configuring clns-4 for other apk /data/app/~~z94R7Ak9huyIXD2pyHEA8g==/com.example.webradio-mEEQJ7kyK9vOm6cZtaD0Nw==/base.apk. target_sdk_version=33, uses_libraries=, library_path=/data/app/~~z94R7Ak9huyIXD2pyHEA8g==/com.example.webradio-mEEQJ7kyK9vOm6cZtaD0Nw==/lib/arm64, permitted_path=/data:/mnt/expand:/data/user/0/com.example.webradio
2023-08-18 13:45:49.759 15249-15249 GraphicsEnvironment com.example.webradio V Currently set values for:
2023-08-18 13:45:49.759 15249-15249 GraphicsEnvironment com.example.webradio V angle_gl_driver_selection_pkgs=[]
2023-08-18 13:45:49.759 15249-15249 GraphicsEnvironment com.example.webradio V angle_gl_driver_selection_values=[]
2023-08-18 13:45:49.759 15249-15249 GraphicsEnvironment com.example.webradio V ANGLE GameManagerService for com.example.webradio: false
2023-08-18 13:45:49.759 15249-15249 GraphicsEnvironment com.example.webradio V com.example.webradio is not listed in per-application setting
2023-08-18 13:45:49.759 15249-15249 GraphicsEnvironment com.example.webradio V Neither updatable production driver nor prerelease driver is supported.
2023-08-18 13:45:49.775 15249-15276 DMABUFHEAPS com.example.webradio I Using DMA-BUF heap named: vframe-secure
2023-08-18 13:45:49.798 15249-15249 Compatibil...geReporter com.example.webradio D Compat change id reported: 210923482; UID 10322; state: ENABLED
2023-08-18 13:45:49.804 15249-15249 MediaPlayer com.example.webradio W Use of stream types is deprecated for operations other than volume control
2023-08-18 13:45:49.804 15249-15249 MediaPlayer com.example.webradio W See the documentation of setAudioStreamType() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2023-08-18 13:45:49.813 15249-15249 Compatibil...geReporter com.example.webradio D Compat change id reported: 237531167; UID 10322; state: DISABLED
2023-08-18 13:45:51.597 15249-15269 MediaPlayerNative com.example.webradio E error (1, -2147483648)
2023-08-18 13:45:51.599 15249-15249 MediaPlayer com.example.webradio E Error (1,-2147483648)
---------------------------- PROCESS ENDED (15249) for package com.example.webradio ----------------------------