我正在为我的应用程序使用Android视频,我不希望媒体控制器隐藏任何帮助
这是我的Java代码
import com.example.androidhive.R;
公共类Activity_Webview扩展了Activity {
ProgressDialog pDialog;
VideoView videoview;
WebView webView;
String url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
// Find your VideoView in your video_main.xml layout
videoview = (VideoView) findViewById(R.id.VideoView);
// Execute StreamVideo AsyncTask
// Create a progressbar
pDialog = new ProgressDialog(Activity_Webview.this);
// Set progressbar title
pDialog.setTitle("Please Wait");
// Set progressbar message
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
// Show progressbar
pDialog.show();
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(videoview.getContext());
mediacontroller.setAnchorView(videoview);
// Get the URL from String VideoURL
url = this.getIntent().getExtras().getString("url");
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(Uri.parse(url));
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoview.start();
}
});
}
} 这是我的XML代码
<VideoView
android:id="@+id/VideoView"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="3"
android:layout_gravity="bottom"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
答案 0 :(得分:0)
mediacontroller.show(0);
以及下面的源代码:
/**
* Show the controller on screen. It will go away
* automatically after 'timeout' milliseconds of inactivity.
* @param timeout The timeout in milliseconds. Use 0 to show
* the controller until hide() is called.
*/
public void show(int timeout) {
if (!mShowing && mAnchor != null) {
setProgress();
if (mPauseButton != null) {
mPauseButton.requestFocus();
}
disableUnsupportedButtons();
updateFloatingWindowLayout();
mWindowManager.addView(mDecor, mDecorLayoutParams);
mShowing = true;
}
updatePausePlay();
// cause the progress bar to be updated even if mShowing
// was already true. This happens, for example, if we're
// paused with the progress bar showing the user hits play.
mHandler.sendEmptyMessage(SHOW_PROGRESS);
if (timeout != 0 && !mAccessibilityManager.isTouchExplorationEnabled()) {
mHandler.removeMessages(FADE_OUT);
Message msg = mHandler.obtainMessage(FADE_OUT);
mHandler.sendMessageDelayed(msg, timeout);
}
}