I have tried this and this for Design Custom Seekbar for ExoPlayer but no luck.
I want to design custom thumb and ProgressBar for ExoPlayer. Following is the XML for ExoPlayer where I've tried to put seekbar but it's not coming as expected.
<com.google.android.exoplayer.AspectRatioFrameLayout
android:id="@+id/video_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<SurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
<View
android:id="@+id/shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:thumb="@drawable/thumb"/>
<com.google.android.exoplayer.text.SubtitleLayout
android:id="@+id/subtitles"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.google.android.exoplayer.AspectRatioFrameLayout>
One more question is how can I have custom volume controls for ExoPlayer like we have it in MXPlayer (vertical bar for volume).
Update
I have got the SeekBar
using this method.
SeekBar seekBar = (SeekBar) mediaController.findViewById(getResources().getIdentifier("mediacontroller_progress","id","android"));
seekBar.setThumb(getResources().getDrawable(R.drawable.player_thumb));
Now the only thing is to get vertical volume control like MXPlayer.
AudioManager is helpful for handling the system volume. I have implemented horizontal volume Seekbar
to control audio volume with ExoPlayer
. Just use this :
Create AudioManager object :
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
Handle Volume up/down Hardware Button :
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN){
volumeSeekBar.setProgress(audioManager.getStreamVolume(exoPlayer.getAudioStreamType()));
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP){
volumeSeekBar.setProgress(audioManager.getStreamVolume(exoPlayer.getAudioStreamType()));
}
return super.onKeyUp(keyCode, event);
}
Handle volume using Seekbar :
volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
audioManager.setStreamVolume(exoPlayer.getAudioStreamType(), i, 0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
I've created a solution which works (at least for me, anyway) and creates a vertical SeekBar. Create Java class like this Hope this will help you.
If I read the ExoPlayer source code correctly you have to keep references to the audioRenderers you use when preparing the ExoPlayer instance.
exoPlayer.prepare(audioRenderer);
To change volume you have to send the following message:
exoPlayer.sendMessage(audioRenderer, MediaCodecAudioTrackRenderer.MSG_SET_VOLUME, 0.1f);
来源:https://stackoverflow.com/questions/34408529/how-to-design-custom-seekbar-and-volume-control-for-exoplayer-in-android