在 Android auto 上播放直播网络电台

问题描述 投票:0回答:1

我正在尝试开发自己的应用程序来在我的手机上播放实时网络广播并使其与 android auto 兼容。因此,我在最新版本的 Android Studio(2022.3.1)上启动了一个新项目 Android auto。

我没有 MP3 文件,只有一个在浏览器中使用的工作 URI:http://streamingp.shoutcast.com/NostalgiePremium-mp3

这是我的java代码,当我运行应用程序时,流应该开始播放(然后我将添加“播放”和“停止”按钮)

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

我尝试了这段代码,应用程序在我的手机上打开,但我没有音乐。

android android-mediaplayer http-live-streaming shoutcast android-automotive
1个回答
0
投票

控制台语音

    ---------------------------- 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 ----------------------------
© www.soinside.com 2019 - 2024. All rights reserved.