setAnchorView ( )源码实例Demo

android.widget.MediaController#setAnchorView ( )源码实例Demo

下面列出了android.widget.MediaController#setAnchorView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DeviceConnect-Android   文件: VideoPlayer.java
@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;
    });
}
 
源代码2 项目: android-tv-leanback   文件: PlayerActivity.java
@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();
}
 
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());
	}
}
 
源代码4 项目: android-tv-leanback   文件: PlayerActivity.java
@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();
}
 
源代码5 项目: MediaPlayer-Extended   文件: VideoViewActivity.java
@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;
}
 
源代码6 项目: android-tv-leanback   文件: PlayerActivity.java
@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();
}
 
源代码7 项目: ResearchStack   文件: ViewVideoActivity.java
@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);
    }
}
 
源代码8 项目: FoodOrdering   文件: Activity_VideoSurveillance.java
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();
        }
    });
}
 
源代码9 项目: ucar-weex-core   文件: WXVideoView.java
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);
  }
}
 
源代码10 项目: weex-uikit   文件: WXVideoView.java
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);
  }
}
 
源代码11 项目: Spectaculum   文件: SpectaculumDemoBaseActivity.java
/**
 * 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);
}
 
源代码12 项目: deltachat-android   文件: VideoPlayer.java
private void initializeVideoViewControls(@NonNull VideoView videoView) {
  MediaController mediaController = new MediaController(getContext());
  mediaController.setAnchorView(videoView);
  mediaController.setMediaPlayer(videoView);

  videoView.setMediaController(mediaController);
}
 
源代码13 项目: Silence   文件: VideoPlayer.java
private void initializeVideoViewControls(@NonNull VideoView videoView) {
  MediaController mediaController = new MediaController(getContext());
  mediaController.setAnchorView(videoView);
  mediaController.setMediaPlayer(videoView);

  videoView.setMediaController(mediaController);
}
 
源代码14 项目: indigenous-android   文件: TimelineVideoActivity.java
@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);
    }
}
 
源代码15 项目: PHONK   文件: VideoPlayerFragment.java
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);
        }

    });

}
 
源代码16 项目: android   文件: PlayerActivity.java
@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();
    }
 
源代码17 项目: Vitamio-Cordova-Plugin   文件: VitamioMedia.java
@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);
    }
}
 
源代码18 项目: Exoplayer_VLC   文件: PlayerActivity.java
@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();

}
 
源代码19 项目: CameraV   文件: MjpegPlayerActivity.java
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();

}
 
源代码20 项目: kolabnotes-android   文件: PreviewFragment.java
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);
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。