Java Code Examples for android.widget.MediaController#setAnchorView()

The following examples show how to use android.widget.MediaController#setAnchorView() . 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: SimpleVideoStream.java    From cordova-plugin-streaming-media with MIT License 8 votes vote down vote up
private void play() {
	mProgressBar.setVisibility(View.VISIBLE);
	Uri videoUri = Uri.parse(mVideoUrl);
	try {
		mVideoView.setOnCompletionListener(this);
		mVideoView.setOnPreparedListener(this);
		mVideoView.setOnErrorListener(this);
		mVideoView.setVideoURI(videoUri);
		mMediaController = new MediaController(this);
		mMediaController.setAnchorView(mVideoView);
		mMediaController.setMediaPlayer(mVideoView);
		if (!mControls) {
			mMediaController.setVisibility(View.GONE);
		}
		mVideoView.setMediaController(mMediaController);
	} catch (Throwable t) {
		Log.d(TAG, t.toString());
	}
}
 
Example 2
Source File: ViewVideoActivity.java    From ResearchStack with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.rsb_activity_video_viewer);

    videoView = (AssetVideoView) findViewById(R.id.videoView);

    MediaController mediaController = new MediaController(this, false);
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    try {
        String videoPath = getIntent().getStringExtra(KEY_RELATIVE_PATH);
        AssetFileDescriptor afd = getAssets().openFd(videoPath);
        videoView.setVideoDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        videoView.start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: VideoPlayer.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    // ReceiverをRegister
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(VideoConst.SEND_HOSTDP_TO_VIDEOPLAYER);
    registerReceiver(mReceiver, mIntentFilter);

    MediaController mMediaController = new MediaController(this);
    mMediaController.setVisibility(View.GONE);
    mMediaController.setAnchorView(mVideoView);

    mVideoView.setMediaController(mMediaController);
    mVideoView.setKeepScreenOn(true);
    mVideoView.setVideoURI(mUri);
    mVideoView.requestFocus();
    mVideoView.setOnCompletionListener(this);
    mVideoView.setOnPreparedListener((mp) -> {
        mVideoView.start();
        mIsReady = true;
    });
}
 
Example 4
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mVideo = (Video) getIntent().getSerializableExtra(Video.INTENT_EXTRA_VIDEO);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    preparePlayer();
}
 
Example 5
Source File: VideoViewActivity.java    From MediaPlayer-Extended with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_videoview);
    Utils.setActionBarSubtitleEllipsizeMiddle(this);

    mVideoView = (VideoView) findViewById(R.id.vv);
    mProgress = (ProgressBar) findViewById(R.id.progress);

    mMediaPlayerControl = mVideoView; //new MediaPlayerDummyControl();
    mMediaController = new MediaController(this);
    mMediaController.setAnchorView(findViewById(R.id.container));
    mMediaController.setMediaPlayer(mMediaPlayerControl);
    mMediaController.setEnabled(false);

    mProgress.setVisibility(View.VISIBLE);

    // Init video playback state (will eventually be overwritten by saved instance state)
    mVideoUri = getIntent().getData();
    mVideoPosition = 0;
    mVideoPlaybackSpeed = 1;
    mVideoPlaying = false;
}
 
Example 6
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mVideo = (Video) getIntent().getSerializableExtra(Video.INTENT_EXTRA_VIDEO);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    preparePlayer();
}
 
Example 7
Source File: PlayerActivity.java    From android-tv-leanback with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    mVideo = (Video) getIntent().getSerializableExtra(Video.INTENT_EXTRA_VIDEO);

    View root = findViewById(R.id.root);
    mediaController = new MediaController(this);

    //overscan safe on 1980 * 1080 TV
    mediaController.setPadding(48, 27, 48, 27);
    mediaController.setAnchorView(root);
    shutterView = findViewById(R.id.shutter);
    surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    preparePlayer();
}
 
Example 8
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 9
Source File: WXVideoView.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private synchronized void createVideoView() {
  if(mVideoView != null){
    return;
  }
  Context context = getContext();
  WXVideoView video = new WXVideoView(context);
  FrameLayout.LayoutParams videoLayoutParams =
      new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.MATCH_PARENT);
  videoLayoutParams.gravity = Gravity.CENTER;
  video.setLayoutParams(videoLayoutParams);
  addView(video, 0);//first child
  video.setOnErrorListener(mOnErrorListener);
  video.setOnPreparedListener(mOnPreparedListener);
  video.setOnCompletionListener(mOnCompletionListener);
  video.setOnVideoPauseListener(mVideoPlayListener);
  MediaController controller = new MediaController(context);
  controller.setAnchorView(this);
  video.setMediaController(controller);
  controller.setMediaPlayer(video);

  mMediaController = controller;
  mVideoView = video;

  if(mUri != null) {
    setVideoURI(mUri);
  }
}
 
Example 10
Source File: WXVideoView.java    From weex-uikit with MIT License 5 votes vote down vote up
private synchronized void createVideoView() {
  if(mVideoView != null){
    return;
  }
  Context context = getContext();
  WXVideoView video = new WXVideoView(context);
  FrameLayout.LayoutParams videoLayoutParams =
      new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
          FrameLayout.LayoutParams.MATCH_PARENT);
  videoLayoutParams.gravity = Gravity.CENTER;
  video.setLayoutParams(videoLayoutParams);
  addView(video, 0);//first child
  video.setOnErrorListener(mOnErrorListener);
  video.setOnPreparedListener(mOnPreparedListener);
  video.setOnCompletionListener(mOnCompletionListener);
  video.setOnVideoPauseListener(mVideoPlayListener);
  MediaController controller = new MediaController(context);
  controller.setAnchorView(this);
  video.setMediaController(controller);
  controller.setMediaPlayer(video);

  mMediaController = controller;
  mVideoView = video;

  if(mUri != null) {
    setVideoURI(mUri);
  }
}
 
Example 11
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 12
Source File: SpectaculumDemoBaseActivity.java    From Spectaculum with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a media controller and attaches it to the activity.
 * This method is for activities that contain a video player.
 * @param mediaPlayerControl the control interface, e.g. a video view
 */
public void initMediaController(MediaController.MediaPlayerControl mediaPlayerControl) {
    mMediaController = new MediaController(this);
    mMediaController.setAnchorView(findViewById(R.id.container));
    mMediaController.setMediaPlayer(mediaPlayerControl);
    mMediaController.setEnabled(false);
}
 
Example 13
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 14
Source File: PlayerActivity.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Intent intent = getIntent();
  contentUri = intent.getData();
  contentType = intent.getIntExtra(CONTENT_TYPE_EXTRA, DemoUtil.TYPE_OTHER);
  contentId = intent.getStringExtra(CONTENT_ID_EXTRA);

  setContentView(R.layout.player_activity);
  View root = findViewById(R.id.root);
  root.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
      if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
        toggleControlsVisibility();
      } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
        view.performClick();
      }
      return true;
    }
  });

  shutterView = findViewById(R.id.shutter);
  debugRootView = findViewById(R.id.controls_root);

  surfaceView = ( SurfaceView) findViewById(R.id.surface_view);
  surfaceView.getHolder().addCallback(this);
  debugTextView = (TextView) findViewById(R.id.debug_text_view);

  playerStateTextView = (TextView) findViewById(R.id.player_state_view);
  subtitleView = (SubtitleView) findViewById(R.id.subtitles);

  mediaController = new MediaController(this);
  mediaController.setAnchorView(root);
  retryButton = (Button) findViewById(R.id.retry_button);
  retryButton.setOnClickListener(this);
  videoButton = (Button) findViewById(R.id.video_controls);
  audioButton = (Button) findViewById(R.id.audio_controls);
  textButton = (Button) findViewById(R.id.text_controls);

  DemoUtil.setDefaultCookieManager();

}
 
Example 15
Source File: TimelineVideoActivity.java    From indigenous-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_timeline_video);
    noVideo = findViewById(R.id.timeline_video_not_video_found);
    videoPlayer = findViewById(R.id.timeline_video);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        final String videoUrl = extras.getString("video");

        if (videoUrl != null) {
            if (videoUrl.contains("youtube.com")) {
                hideVideoPlayer(false);
                TextView youtubeVideo = findViewById(R.id.timeline_video_youtube);
                youtubeVideo.setVisibility(View.VISIBLE);
                youtubeVideo.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setData(Uri.parse(videoUrl));
                        startActivity(i);
                    }
                });
            }
            else {
                videoPlayer.setVideoPath(videoUrl);
                videoPlayer.canPause();
                mediaController = new MediaController(this);
                mediaController.setAnchorView(videoPlayer);
                videoPlayer.setMediaController(mediaController);
                videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()  {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        mediaController.show();
                        if (Preferences.getPreference(TimelineVideoActivity.this, "pref_key_video_autoplay", false)) {
                            videoPlayer.start();
                        }
                    }
                });
            }
        }
        else {
            hideVideoPlayer(true);
        }
    }
    else {
        hideVideoPlayer(true);
    }
}
 
Example 16
Source File: VitamioMedia.java    From Vitamio-Cordova-Plugin with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
        return;

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    extras = getIntent().getExtras();

    // handle extras
    if (extras == null) {
        wrapItUp(RESULT_CANCELED, "Error: No options provided");
    } else {
        if (extras.containsKey("isStreaming")) {
           isStreaming = extras.getBoolean("isStreaming");
        }

        if (extras.containsKey("shouldAutoClose")) {
            mShouldAutoClose = extras.getBoolean("shouldAutoClose");
        }

        mMediaType = extras.getString("type");
        if (mMediaType == null) mMediaType = MEDIA_TYPE_VIDEO;

        mMediaPlayer = new MediaPlayer(this);
        mMediaController = new MediaController(this, !isStreaming);
        mMediaController.setMediaPlayer(this);
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnErrorListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);

        RelativeLayout relLayout = new RelativeLayout(this);

        if (extras.containsKey("bgColor")) {
            try {
                bgColor = Color.parseColor(extras.getString("bgColor"));
            } catch (Exception e) {
                Log.v(TAG, "Error parsing color");
                Log.e(TAG, e.toString());
                bgColor = DEFAULT_BG_COLOR;
            }
        }
        relLayout.setBackgroundColor(bgColor);

        RelativeLayout.LayoutParams relLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        relLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        mMediaView = new SurfaceView(this);
        mMediaView.setLayoutParams(relLayoutParam);
        relLayout.addView(mMediaView);

        mProgressBar = new ProgressBar(this);
        mProgressBar.setIndeterminate(true);
        mProgressBar.setVisibility(View.VISIBLE);
        RelativeLayout.LayoutParams pblp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        pblp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        mProgressBar.setLayoutParams(pblp);
        relLayout.addView(mProgressBar);
        mProgressBar.bringToFront();

        mMediaController.setAnchorView(relLayout);
        mMediaController.setEnabled(true);
        if (mMediaType.equalsIgnoreCase(MEDIA_TYPE_AUDIO)) {
            mMediaView.setBackgroundColor(bgColor);
            if (extras.containsKey("bgImage")) {
                if (extras.containsKey("bgImageScaleType")) {
                    String scaleType = extras.getString("bgImageScaleType");
                    if (scaleType.equalsIgnoreCase("fit")) {
                        bgImageScaleType = ImageView.ScaleType.FIT_CENTER;
                    } else if (scaleType.equalsIgnoreCase("stretch")) {
                        bgImageScaleType = ImageView.ScaleType.FIT_XY;
                    } else {
                        bgImageScaleType = ImageView.ScaleType.CENTER;
                    }
                }
                bgImage = new ImageView(this);
                new ImageLoadTask(extras.getString("bgImage"), this).execute(null, null);
                RelativeLayout.LayoutParams bgImageLayoutParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                bgImageLayoutParam.addRule(RelativeLayout.CENTER_IN_PARENT);
                bgImage.setLayoutParams(bgImageLayoutParam);
                bgImage.setScaleType(bgImageScaleType);
                relLayout.addView(bgImage);
            }
        }
        setContentView(relLayout, relLayoutParam);
        holder = mMediaView.getHolder();
        holder.addCallback(this);
        holder.setFormat(PixelFormat.RGBA_8888);
    }
}
 
Example 17
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 18
Source File: VideoPlayerFragment.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
public void loadVideo(final String path) {
    /*
     * Alternatively,for streaming media you can use
     * mVideoView.setVideoURI(Uri.parse(URLstring));
     */

    mVideoView.setVideoPath(path);
    MediaController mediaController = new MediaController(c);
    mediaController.setAnchorView(mVideoView);
    mVideoView.setMediaController(null);

    mVideoView.requestFocus();
    mVideoView.setKeepScreenOn(true);

    mVideoView.start();

    mVideoView.setOnClickListener(v -> close());

    mVideoView.setOnPreparedListener(new OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp_ = mp;
            mp_.setLooping(true);

            // mVideoView.animate().rotation(200).alpha((float) 0.5)
            // .scaleX(0.2f).scaleY(0.2f).setDuration(2000);

            r = new Runnable() {

                @Override
                public void run() {
                    for (VideoListener l : listeners) {
                        try {
                            l.onTimeUpdate(mp_.getCurrentPosition(), mp_.getDuration());

                        } catch (Exception e) {
                        }

                    }
                    handler.postDelayed(this, 1000);
                }
            };

            handler.post(r);
        }
    });

    // mp_.setO

    mVideoView.setOnCompletionListener(mp -> {

        // finish();
        for (VideoListener l : listeners) {
            l.onFinish(true);
        }

    });

}
 
Example 19
Source File: PreviewFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 3 votes vote down vote up
void displayVideo(ActiveAccount account, String noteUID,Attachment attachment){
    videoView.setVisibility(View.VISIBLE);

    MediaController mediaController = new MediaController(getActivity());
    mediaController.setAnchorView(videoView);

    videoView.setMediaController(mediaController);

    videoView.setVideoURI(attachmentRepository.getUriFromAttachment(account.getAccount(), account.getRootFolder(), noteUID, attachment));

    mediaController.show(0);
}
 
Example 20
Source File: MjpegPlayerActivity.java    From CameraV with GNU General Public License v3.0 3 votes vote down vote up
private void initVideo (InputStream is)
{

	videoView = (MjpegView) findViewById(R.id.videoView1);
	MediaController mediaController = new MediaController(this);
	mediaController.setAnchorView(videoView);

	videoView.setMediaController(mediaController);

	videoView.setSource(new MjpegInputStream(is, getCacheDir()));
	videoView.start();

}