0
還有就是通過ExoPlayer 2.播放音頻,從互聯網來電時聲音靜音0怎樣使,和代碼,當通話結束,回到原來的?靜音
public class Player extends AppCompatActivity {
private String stream;
private boolean isPlay;
private ImageButton btnPLayPause;
BandwidthMeter bandwidthMeter;
TrackSelector trackSelector;
SimpleExoPlayer player;
private SimpleExoPlayerView simpleExoPlayerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
btnPLayPause = (ImageButton) findViewById(R.id.btnPLayPause);
stream = "http://site.ru/radio.mp3";
bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory streamSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
trackSelector = new DefaultTrackSelector(streamSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl());
simpleExoPlayerView = new SimpleExoPlayerView(this);
simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
simpleExoPlayerView.setUseController(true);
simpleExoPlayerView.requestFocus();
simpleExoPlayerView.setPlayer(player);
Uri streamUri = Uri.parse(stream);
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"), bandwidthMeter);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(streamUri, dataSourceFactory, extractorsFactory, null, null);
player.prepare(mediaSource);
player.setPlayWhenReady(true);
isPlay = true;
if (player.getPlayWhenReady() == true) {
btnPLayPause.setImageResource(R.drawable.icon_stop);
}
}
@Override
protected void onDestroy() {
NotificationManager notifManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notifManager.cancelAll();
super.onDestroy();
player.release();
}
public void onPlayPause(View view) {
if (isPlay == true) {
if (player.getPlayWhenReady() == true) {
player.setPlayWhenReady(false);
isPlay = false;
btnPLayPause.setImageResource(R.drawable.icon_play);
}
} else if (isPlay == false) {
if (player.getPlayWhenReady() == false) {
player.setPlayWhenReady(true);
isPlay = true;
btnPLayPause.setImageResource(R.drawable.icon_stop);
}
}
}
}
人們希望舉一個例子,或者一個類似的例子