我使用exoplayer来流式传输视频文件视频播放正确,但当我试图实现手势控制,如向上滑动,向下滑动,双击应用程序崩溃。简单地说,当我刷上或刷下的应用程序崩溃和双击是不工作的。我的exoplayer活动
GESTURECONTROLLER gcont = new GESTURECONTROLLER();
gcont.setActivity(this);
gestureDetectorCompat = new GestureDetectorCompat(this, gcont);
LoadControl loadControl = new DefaultLoadControl();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
playerView.setPlayer(simpleExoPlayer);
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "demo"));
MediaSource contentMediaSource = buildMediaSource(streamLink);
MediaSource[] mediaSources = new MediaSource[1];
mediaSources[0] = contentMediaSource;
MediaSource mediaSource = new MergingMediaSource(mediaSources);
simpleExoPlayer.prepare(mediaSource);
simpleExoPlayer.setPlayWhenReady(true);
playerView.setKeepScreenOn(true);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
gestureDetectorCompat.onTouchEvent(event);
return true;
}
public void ifDoubleTap() {
Toast.makeText(this, "I double tap", Toast.LENGTH_SHORT).show();
}
public void ifSwipeLeft() {
Toast.makeText(this, "I swipe Left", Toast.LENGTH_SHORT).show();
}
public void ifSwipeRight() {
Toast.makeText(this, "I swipe Right", Toast.LENGTH_SHORT).show();
}
public void ifSwipeUp() {
Toast.makeText(this, "I swipe Up", Toast.LENGTH_SHORT).show();
}
public void ifSwipeDown() {
Toast.makeText(this, "I swipe Down", Toast.LENGTH_SHORT).show();
}
我的手势控制器类
public class GESTURECONTROLLER extends GestureDetector.SimpleOnGestureListener {
private static int MIN_SWIPE_DISTANCE_X = 100;
private static int MIN_SWIPE_DISTANCE_Y = 100;
private static int MAX_SWIPE_DISTANCE_X = 1000;
private static int MAX_SWIPE_DISTANCE_Y = 1000;
private MainActivity activity = null;
public MainActivity getActivity(){
return activity;
}
public void setActivity(MainActivity activity){
this.activity = activity;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float deltaX = e1.getX() - e2.getX();
float deltaY = e1.getY() - e2.getY();
float deltaXabs = Math.abs(deltaX);
float deltaYabs = Math.abs(deltaY);
if (deltaXabs >= MIN_SWIPE_DISTANCE_X && deltaXabs <= MAX_SWIPE_DISTANCE_X){
if(deltaX > 0 ) {
//Swipe Left
this.activity.ifSwipeLeft();
} else {
//Swipe Right
this.activity.ifSwipeRight();
}
}
if (deltaYabs >= MIN_SWIPE_DISTANCE_Y && deltaYabs <= MAX_SWIPE_DISTANCE_Y){
if(deltaY > 0 ) {
//Swipe Up
this.activity.ifSwipeUp();
} else {
//Swipe Down
this.activity.ifSwipeDown();
}
}
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
this.activity.IfSingletap();
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
this.activity.ifDoubleTap();
return true;
}
我知道默认的触摸控制来硬编码的exoplayer库,但我可以禁用,并使用此控件代替
暂无答案!
目前还没有任何答案,快来回答吧!