禁用 mediacontroller android 的前向和后向搜索?
Disable seekforward and seekbackward of mediacontroller android?
我正在播放来自 url 的视频,我想禁用视频的搜索栏跟踪。怎么办。
这是我的代码:
videoUrl = "http://download.itcuties.com/teaser/itcuties-teaser-480.mp4";
videoview.setVideoPath(videoUrl);
mediaController = new MediaController(this, false);
int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
seekBarVideo=(SeekBar)mediaController.findViewById(topContainerId);
seekBarVideo.setEnabled(false);
mediaController.setAnchorView(videoview);
videoview.setMediaController(mediaController);
应用程序崩溃:seekBarVideo.setEnabled(false);
java.lang.NullPointerException
at com.vfirst.offers.VideoBufferActivity.onClick(VideoBufferActivity.java:93)
at android.view.View.performClick(View.java:4575)
at android.view.View$PerformClick.run(View.java:18578)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5127)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
您可以尝试创建一个没有搜索栏的自定义媒体控制器 UI。检查这个 post
how to create custom UI for android MediaController
或尝试破解,获得对搜索栏的访问权限并将可见性设置为 GONE
final int progressBarId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
final SeekBar seekbar = (SeekBar) mController.findViewById(progressBarId);
编辑
尝试循环遍历 MediaController 中的子视图,直到找到搜索栏,然后将其隐藏
private void styleMediaController(View view) {
if (view instanceof MediaController) {
MediaController v = (MediaController) view;
for(int i = 0; i < v.getChildCount(); i++) {
styleMediaController(v.getChildAt(i));
}
} else
if (view instanceof LinearLayout) {
LinearLayout ll = (LinearLayout) view;
for(int i = 0; i < ll.getChildCount(); i++) {
styleMediaController(ll.getChildAt(i));
}
} else if (view instanceof SeekBar) {
// set progress bar color
SeekBar seeker = (SeekBar) view;
//hide seekbar here
}
}
能够在这个帮助下解决
需要在 videoview
的 onPreparedListener 中获取 seekbar
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
seekBarVideo = (SeekBar) mediaController.findViewById(topContainerId);
seekBarVideo.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
seekBar.setEnabled(false);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
seekBar.setEnabled(false);
}
});
}
});
我正在播放来自 url 的视频,我想禁用视频的搜索栏跟踪。怎么办。
这是我的代码:
videoUrl = "http://download.itcuties.com/teaser/itcuties-teaser-480.mp4";
videoview.setVideoPath(videoUrl);
mediaController = new MediaController(this, false);
int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
seekBarVideo=(SeekBar)mediaController.findViewById(topContainerId);
seekBarVideo.setEnabled(false);
mediaController.setAnchorView(videoview);
videoview.setMediaController(mediaController);
应用程序崩溃:seekBarVideo.setEnabled(false);
java.lang.NullPointerException
at com.vfirst.offers.VideoBufferActivity.onClick(VideoBufferActivity.java:93)
at android.view.View.performClick(View.java:4575)
at android.view.View$PerformClick.run(View.java:18578)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5127)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
您可以尝试创建一个没有搜索栏的自定义媒体控制器 UI。检查这个 post how to create custom UI for android MediaController
或尝试破解,获得对搜索栏的访问权限并将可见性设置为 GONE
final int progressBarId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
final SeekBar seekbar = (SeekBar) mController.findViewById(progressBarId);
编辑
尝试循环遍历 MediaController 中的子视图,直到找到搜索栏,然后将其隐藏
private void styleMediaController(View view) {
if (view instanceof MediaController) {
MediaController v = (MediaController) view;
for(int i = 0; i < v.getChildCount(); i++) {
styleMediaController(v.getChildAt(i));
}
} else
if (view instanceof LinearLayout) {
LinearLayout ll = (LinearLayout) view;
for(int i = 0; i < ll.getChildCount(); i++) {
styleMediaController(ll.getChildAt(i));
}
} else if (view instanceof SeekBar) {
// set progress bar color
SeekBar seeker = (SeekBar) view;
//hide seekbar here
}
}
能够在这个帮助下解决
需要在 videoview
的 onPreparedListener 中获取 seekbar videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
seekBarVideo = (SeekBar) mediaController.findViewById(topContainerId);
seekBarVideo.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
seekBar.setEnabled(false);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
seekBar.setEnabled(false);
}
});
}
});