我已经开发了android应用程序无线电数据流。
我的应用程序在音乐播放上运行良好,所以我想添加电台直播流网址,如:http://162.244.80.118:4900/;stream.mp3
所以任何人都可以帮助我如何添加网址和播放现场广播应用程序的背景音乐service。
下面是我用来在安卓背景音乐上播放音乐开始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();
}
}发布于 2017-10-18 15:52:51
你可以使用ExoPlayer,这是一个建立在安卓低级媒体API之上的应用级媒体播放器,你可以创建它来从service.Please中流式播放。请参考这个链接了解实现部分。https://github.com/ayalus/ExoPlayer-2-Example/blob/master/ExoPlayer2Example/app/src/main/java/com/ayalus/exoplayer2example/MainActivity.java
https://stackoverflow.com/questions/46380034
复制相似问题