如何使用Android应用中的实时流URL开始服务背景音乐



我已经开发了Android App Radio流。

我的应用在音乐播放上正常工作,所以我想添加电台实时流url,例如:http://162.244.80.118:4900/;Stream.mp3

这样,任何人都可以帮助我添加URL并播放背景音乐service用于实时广播应用。

这是我在Android背景音乐上播放的启动service代码

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.provider.Settings;
import android.support.annotation.Nullable;
/**
 * Created by User on 9/22/2017.
 */
public class MyService extends Service {
    private MediaPlayer player;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        player = MediaPlayer.create(this, Settings.System.DEFAULT_RINGTONE_URI);
        player.setLooping(true);
        player.start();
        return START_STICKY;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        player.stop();
    }
}

您可以使用exoplayer,这是构建在Android低级媒体API上的应用级媒体播放器,您可以创建它以从服务流式传输。请参阅此链接以进行实现部分。https://github.com/ayalus-coplayer-2-example/blob/master/master/exoplayer2example/app/src/src/main/java/java/com/AYALUS/AYALUS/EXOPLAYER2EXAMPLIVITIVE.JAVA

最新更新