Java Code Examples for android.widget.VideoView#setMediaController()

The following examples show how to use android.widget.VideoView#setMediaController() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiveStuff.java    From goprohero with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_live_stuff);
    myVideoView = (VideoView)this.findViewById(R.id.videoView);
    MediaController mc = new MediaController(this);
    myVideoView.setMediaController(mc);
    urlStream = "http://10.5.5.9:8080/live/amba.m3u8";
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            myVideoView.setVideoURI(Uri.parse(urlStream));
            myVideoView.start();
        }

    });

}
 
Example 2
Source File: VideoViewDemo.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.videoview);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    if (path == "") {
        // Tell the user to provide a media file URL/path.
        Toast.makeText(
                VideoViewDemo.this,
                "Please edit VideoViewDemo Activity, and set path"
                        + " variable to your media file URL/path",
                Toast.LENGTH_LONG).show();

    } else {

        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

    }
}
 
Example 3
Source File: Activity_VideoSurveillance.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
private void initView() {
    pg=new ProgressDialog(Activity_VideoSurveillance.this);
    pg.setMessage("缓冲中...");
    pg.show();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    TextView toolbarText = (TextView) findViewById(R.id.toolbar_text);
    toolbarText.setText("视频监控");
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (!Util.checkNetwork(this)) {
        return;
    }
    videoViewVideo = (VideoView) findViewById(R.id.videoViewVideo);

    try {
        //设置视频控制器
        MediaController mediacontroller = new MediaController(Activity_VideoSurveillance.this);
        mediacontroller.setAnchorView(videoViewVideo);
        videoViewVideo.setMediaController(mediacontroller);
        //视频来源
        videoViewVideo.setVideoURI(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
    } catch (Exception e) {
        e.printStackTrace();
        pg.dismiss();
    }
    videoViewVideo.requestFocus();
    videoViewVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pg.dismiss();
            //开始播放视频
            videoViewVideo.start();
        }
    });
}
 
Example 4
Source File: VideocastActivity.java    From AnotherRSS with The Unlicense 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_videoweb);
    VideoView videoView = (VideoView) findViewById(R.id.videoView);
    WebView webView = (WebView) findViewById(R.id.webView);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    Intent intent = getIntent();
    Uri uri = intent.getData();
    if (uri != null) {
        String url = uri.toString();
        if (url.endsWith(".mp4")) {
            webView.setVisibility(View.GONE);
            progressBar.setVisibility(View.GONE);
            videoView.setVisibility(View.VISIBLE);
            videoView.setMediaController(AnotherRSS.mediaController);
            videoView.setVideoURI(uri);
            videoView.requestFocus();
            videoView.start();
        } else {
            webView.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.VISIBLE);
            videoView.setVisibility(View.GONE);
            webView.setWebViewClient(new MyWebClient());
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setUseWideViewPort(true);
            webView.loadUrl(url);
        }
    }
}
 
Example 5
Source File: VideoFragment.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mMediaController = new MediaController(getContext());
    mVideoView = (VideoView) view.findViewById(R.id.video);
    mVideoView.setVideoPath(mVideoUrl);
    mVideoView.setMediaController(mMediaController);
    mVideoView.requestFocus();
}
 
Example 6
Source File: VideoPlayer.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void initializeVideoViewControls(@NonNull VideoView videoView) {
  MediaController mediaController = new MediaController(getContext());
  mediaController.setAnchorView(videoView);
  mediaController.setMediaPlayer(videoView);

  videoView.setMediaController(mediaController);
}
 
Example 7
Source File: LiveStuff.java    From goprohero with MIT License 5 votes vote down vote up
public void restartStream(View view){
    myVideoView = (VideoView)this.findViewById(R.id.videoView);
    MediaController mc = new MediaController(this);
    myVideoView.setMediaController(mc);
    urlStream = "http://10.5.5.9:8080/live/amba.m3u8";
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            myVideoView.setVideoURI(Uri.parse(urlStream));
            myVideoView.setMediaController(null);
            myVideoView.start();
        }

    });
}
 
Example 8
Source File: VideoPlayer.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private void initializeVideoViewControls(@NonNull VideoView videoView) {
  MediaController mediaController = new MediaController(getContext());
  mediaController.setAnchorView(videoView);
  mediaController.setMediaPlayer(videoView);

  videoView.setMediaController(mediaController);
}
 
Example 9
Source File: AudioVideoVideoPlayActivity.java    From coursera-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	// Get a reference to the VideoView
	
	mVideoView = (VideoView) findViewById(R.id.videoViewer);

	// Add a Media controller to allow forward/reverse/pause/resume 
	
	final MediaController mMediaController = new MediaController(
			AudioVideoVideoPlayActivity.this, true);
	
	mMediaController.setEnabled(false);

	mVideoView.setMediaController(mMediaController);
	
	mVideoView
			.setVideoURI(Uri
					.parse("android.resource://course.examples.AudioVideo.VideoPlay/raw/moon"));
	
	// Add an OnPreparedListener to enable the MediaController once the video is ready
	mVideoView.setOnPreparedListener(new OnPreparedListener() {

		@Override
		public void onPrepared(MediaPlayer mp) {
			mMediaController.setEnabled(true);
		}
	});
}
 
Example 10
Source File: FullScreenVideoUtil.java    From appinventor-extensions with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the dialog for displaying a fullscreen VideoView.
 *
 * @return The created Dialog
 */
public Dialog createFullScreenVideoDialog() {

  if (mFullScreenVideoBundle == null)
    Log.i("Form.createFullScreenVideoDialog", "mFullScreenVideoBundle is null");

  mFullScreenVideoView = new VideoView(mForm);
  mFullScreenVideoHolder = new FrameLayout(mForm);
  mFullScreenVideoController = new CustomMediaController(mForm);

  mFullScreenVideoView.setId(mFullScreenVideoView.hashCode());
  mFullScreenVideoHolder.setId(mFullScreenVideoHolder.hashCode());

  mFullScreenVideoView.setMediaController(mFullScreenVideoController);

  mFullScreenVideoView.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
      Log.i("FullScreenVideoUtil..onTouch", "Video Touched!!");
      return false;
    }
  });
  mFullScreenVideoController.setAnchorView(mFullScreenVideoView);

  String orientation = mForm.ScreenOrientation();
  if (orientation.equals("landscape")
      || orientation.equals("sensorLandscape")
      || orientation.equals("reverseLandscape")) {
    mFullScreenVideoView.setLayoutParams(new FrameLayout.LayoutParams(
        FrameLayout.LayoutParams.WRAP_CONTENT,
        FrameLayout.LayoutParams.FILL_PARENT, Gravity.CENTER));
  } else {
    mFullScreenVideoView.setLayoutParams(new FrameLayout.LayoutParams(
        FrameLayout.LayoutParams.FILL_PARENT,
        FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
  }
  mFullScreenVideoHolder
      .setLayoutParams(new ViewGroup.LayoutParams(
          ViewGroup.LayoutParams.FILL_PARENT,
          ViewGroup.LayoutParams.FILL_PARENT));

  mFullScreenVideoHolder.addView(mFullScreenVideoView);

  // Add the MediaController to the Dialog
  mFullScreenVideoController.addTo(mFullScreenVideoHolder,
      mMediaControllerParams);

  mFullScreenVideoDialog.setContentView(mFullScreenVideoHolder);
  return mFullScreenVideoDialog;
}
 
Example 11
Source File: PlayerActivity.java    From android with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        url = getIntent().getStringExtra(KEY_URL);
        url = "http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4";
        if (url == null && savedInstanceState != null) {
            url = savedInstanceState.getString(KEY_URL);
        }

        if (url == null) {
            Toast.makeText(getApplicationContext(), TOAST_ERROR_URL, Toast.LENGTH_LONG).show();
            finish();
            return;
        }

        setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);

        videoView = new VideoView(this);
        videoView.setVideoURI(Uri.parse(url));
        videoView.requestFocus();
        videoView.setOnPreparedListener(this);
        videoView.setOnCompletionListener(this);
        videoView.setOnErrorListener(this);

        mc = new MediaController(this);
        mc.setAnchorView(videoView);
        mc.setKeepScreenOn(true);

        videoView.setMediaController(mc);

        llMain = new LinearLayout(this);
        llMain.setGravity(Gravity.CENTER_VERTICAL);
        llMain.setOrientation(LinearLayout.VERTICAL);
        llMain.setLayoutParams(params);

        llMain.addView(videoView, params);
        setContentView(llMain);

        initDialog();
    }
 
Example 12
Source File: CumulusVideoPlayback.java    From CumulusTV with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /* Doing it the native way */
    Intent parameters = getIntent();
    if(parameters == null) {
        setContentView(R.layout.fullvideo);//***************
        myVideoView = (VideoView) this.findViewById(R.id.myVideoView);
        MediaController mc = new MediaController(this);
        myVideoView.setMediaController(mc);
        String ABCNews = "http://abclive.abcnews.com/i/abc_live4@136330/index_1200_av-b.m3u8";
        String Brazil = "http://stream331.overseebrasil.com.br/live_previd_155/_definst_/live_previd_155/playlist.m3u8";
        String NASA = "http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8";
        urlStream = ABCNews;
        Log.d(TAG, "About to open " + urlStream.toString());
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG, "On UI Thread");
                myVideoView.setVideoURI(Uri.parse(urlStream));
                Log.d(TAG, "Now play");
                myVideoView.start();
            }
        });
    } else {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        getSupportActionBar().hide();

        updateLauncherShortcut();

        urlStream = parameters.getStringExtra(KEY_VIDEO_URL);
        if(!urlStream.isEmpty()) {
            mTvPlayer = new CumulusTvPlayer(this);
            setContentView(R.layout.full_surfaceview);
            SurfaceView sv = (SurfaceView) findViewById(R.id.surface);
            mTvPlayer.setSurface(sv.getHolder().getSurface());
            mTvPlayer.setVolume(1);
            mTvPlayer.registerErrorListener(new CumulusTvPlayer.ErrorListener() {
                @Override
                public void onError(Exception error) {
                    Log.e(TAG, error.toString());
                    if(error instanceof MediaSourceFactory.NotMediaException) {
                        Log.d(TAG, "Cannot play the stream, try loading it as a website");
                        Toast.makeText(CumulusVideoPlayback.this,
                                R.string.msg_open_web,
                                Toast.LENGTH_SHORT).show();
                        CumulusWebPlayer wv = new CumulusWebPlayer(CumulusVideoPlayback.this,
                                new CumulusWebPlayer.WebViewListener() {
                            @Override
                            public void onPageFinished() {
                                //Don't do anything
                            }
                        });
                        wv.load(urlStream);
                        setContentView(wv);
                    }
                }
            });
            Log.d(TAG, "Start playing " + urlStream);
            mTvPlayer.startPlaying(Uri.parse(urlStream));
            mTvPlayer.play();
        } else {
            Toast.makeText(this, R.string.msg_no_url_found, Toast.LENGTH_SHORT).show();
            finish();
        }
    }
}
 
Example 13
Source File: VideoPlayerActivity.java    From media-for-mobile with Apache License 2.0 3 votes vote down vote up
private void init() {
    mVideoView = (VideoView) findViewById(R.id.video_view);

    mVideoController = new MediaController(this, false);

    mVideoView.setMediaController(mVideoController);

    mVideoView.requestFocus();
    mVideoView.setZOrderOnTop(true);
}