List of usage examples for android.widget MediaController MediaController
public MediaController(Context context)
From source file:com.chute.android.photopickerplustutorial.activity.VideoPlayerActivity.java
private void initVideo(String url) { videoView = (VideoView) findViewById(R.id.videoView); MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); Uri uri = Uri.parse(url);//from ww w . j a v a2 s. com videoView.setMediaController(mediaController); videoView.setVideoURI(uri); videoView.requestFocus(); videoView.start(); }
From source file:sample.videoview.kevalpatel.com.userawarevideoview.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //set the is tracking indicator mTrackingStatusIv = (ImageView) findViewById(R.id.eye_tracking); mTrackingStatusIv.setVisibility(View.GONE); //set user aware video view mVideoView = (UserAwareVideoView) findViewById(R.id.video_view); mVideoView.setUserAwarenessListener(this); mVideoView.setVideoURI(Uri.parse("http://clips.vorwaerts-gmbh.de/VfE_html5.mp4")); //attach tge media controller MediaController mediaController = new MediaController(this); mediaController.setAnchorView(mVideoView); mediaController.setPrevNextListeners(new View.OnClickListener() { @Override//ww w .j a va2 s .c o m public void onClick(View view) { mVideoView.stopPlayback(); mVideoView.start(); } }, new View.OnClickListener() { @Override public void onClick(View view) { mVideoView.stopPlayback(); mVideoView.start(); } }); mVideoView.setMediaController(mediaController); //Start video playing. This will start the user eye tracking too. //Do not care about permissions. Permissions will check internally. //Just handle errors. mVideoView.start(); }
From source file:com.yahoo.hakunamatata.fragments.GuideFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (bgRes == R.drawable.gd4) { getView().findViewById(R.id.image).setVisibility(View.GONE); // getView().findViewById(R.id.youtubeplayerfragment_container).setVisibility(View.VISIBLE); VideoView videoView = (VideoView) getView().findViewById(R.id.videoview); getView().findViewById(R.id.image).setVisibility(View.GONE); videoView.setVisibility(View.VISIBLE); //if you want the controls to appear videoView.setMediaController(new MediaController(getActivity())); Uri video = Uri//w w w .ja va2 s . c om .parse("android.resource://" + getActivity().getPackageName() + "/" + R.raw.lionlaughhahahaha); //do not add any extension //if your file is named sherif.mp4 and placed in /raw //use R.raw.sherif videoView.setVideoURI(video); videoView.start(); // PlayerYouTubeFrag youTubePlayerFragment = PlayerYouTubeFrag.newInstance("https://www.youtube.com/watch?v=VPRuL9ACZeM"); // getChildFragmentManager().beginTransaction().add(R.id.youtubeplayerfragment_container, youTubePlayerFragment).commit(); // getChildFragmentManager().executePendingTransactions(); // youTubePlayerFragment.init(); } else { imageView = (ImageView) getView().findViewById(R.id.image); Picasso.with(getActivity().getBaseContext()).load(bgRes).into(imageView); } //imageView.setBackgroundResource(bgRes); }
From source file:com.manning.androidhacks.hack014.MainActivity.java
private void initVideoView() { mVideoView.setMediaController(new MediaController(this)); Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bigbuck); mVideoView.setVideoURI(uri);// w w w . j a va2s . c o m setVideoViewPosition(); mVideoView.start(); }
From source file:bentaang.chonlakant.com.drawer.fragment.VideoViewNativeFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.videoview_native, container, false); //mEditText = (EditText) rootView.findViewById(R.id.url); mVideoView = (VideoView) rootView.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(); //return; } else {/* ww w .j ava 2s.c o m*/ /* * Alternatively,for streaming media you can use * mVideoView.setVideoURI(Uri.parse(URLstring)); */ mVideoView.setVideoPath(path); mVideoView.setMediaController(new MediaController(getActivity())); mVideoView.requestFocus(); mVideoView.start(); mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mediaPlayer) { } }); } return rootView; }
From source file:com.jlcsoftware.callrecorder.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); checkPermissions();//from ww w.j a v a 2 s .c o m Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); //set up MediaPlayer mediaController = new MediaController(this); mediaPlayer = new MediaPlayer(); mediaPlayer.setOnPreparedListener(this); mediaPlayer.setOnCompletionListener(this); RateMeNowDialog.showRateDialog(this, 10); }
From source file:edu.mit.mobile.android.locast.ver2.casts.VideoPlayer.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.videoplayer); mVideoView = (VideoView) findViewById(R.id.video); mMediaController = new MediaController(this); mMediaController.setMediaPlayer(mVideoView); mMediaController.setAnchorView(mVideoView); mVideoView.setOnPreparedListener(this); mVideoView.setOnErrorListener(this); mVideoView.setOnCompletionListener(this); mVideoView.setMediaController(mMediaController); mDescriptionView = (TextView) findViewById(R.id.description); mTitleView = (TextView) findViewById(R.id.title); final Intent intent = getIntent(); final String action = intent.getAction(); final String type = intent.resolveType(this); final LoaderManager lm = getSupportLoaderManager(); setProgressBar(true);//from ww w .j a v a2 s.c o m if (MediaProvider.TYPE_CASTMEDIA_DIR.equals(type)) { lm.initLoader(LOADER_CASTMEDIA_DIR, null, this); } else if (MediaProvider.TYPE_CASTMEDIA_ITEM.equals(type)) { lm.initLoader(LOADER_CASTMEDIA_ITEM, null, this); } adjustForOrientation(getResources().getConfiguration()); }
From source file:com.ternup.caddisfly.activity.VideoActivity.java
private void playVideo(File videoFile) { DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); int height = dm.heightPixels; int width = dm.widthPixels; final VideoView videoHolder = (VideoView) this.findViewById(R.id.video_player_view); videoHolder.setMinimumWidth(width);/* w ww . j a v a 2s. c o m*/ videoHolder.setMinimumHeight(height); //getWindow().setFormat(PixelFormat.TRANSLUCENT); videoHolder.setMediaController(new MediaController(this)); videoHolder.setVideoPath(videoFile.getAbsolutePath()); videoHolder.requestFocus(); videoHolder.start(); }
From source file:uk.ac.hutton.ics.buntata.activity.VideoActivity.java
@Override protected void onResume() { super.onResume(); if (player == null) { try {/*from ww w. j av a2 s .c om*/ player = new MediaPlayer(); player.setDataSource(this, uri); mediaController = new MediaController(this); sv.getHolder().addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { player.setDisplay(holder); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { player.setDisplay(holder); } @Override public void surfaceDestroyed(SurfaceHolder holder) { } }); player.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() { @Override public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { // // Get the dimensions of the video int videoWidth = player.getVideoWidth(); int videoHeight = player.getVideoHeight(); float videoProportion = (float) videoWidth / (float) videoHeight; // Get the width of the screen Point point = new Point(); getWindowManager().getDefaultDisplay().getSize(point); int screenWidth = point.x; int screenHeight = point.y; float screenProportion = (float) screenWidth / (float) screenHeight; // Get the SurfaceView layout parameters ViewGroup.LayoutParams lp = sv.getLayoutParams(); if (videoProportion > screenProportion) { lp.width = screenWidth; lp.height = (int) ((float) screenWidth / videoProportion); } else { lp.width = (int) (videoProportion * (float) screenHeight); lp.height = screenHeight; } // Commit the layout parameters sv.setLayoutParams(lp); player.start(); } }); player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mediaController.setMediaPlayer(VideoActivity.this); mediaController.setAnchorView(sv); } }); player.prepare(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:edu.mit.mobile.android.locast.casts.VideoPlayer.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.videoplayer); mVideoView = (VideoView) findViewById(R.id.video); mMediaController = new MediaController(this); mMediaController.setMediaPlayer(mVideoView); mMediaController.setAnchorView(mVideoView); mVideoView.setOnPreparedListener(this); mVideoView.setOnErrorListener(this); mVideoView.setOnCompletionListener(this); mVideoView.setMediaController(mMediaController); mDescriptionView = (TextView) findViewById(R.id.description); mTitleView = (TextView) findViewById(R.id.title); final Intent intent = getIntent(); final String action = intent.getAction(); if (!Intent.ACTION_VIEW.equals(action)) { Toast.makeText(this, R.string.error_cast_could_not_play_video, Toast.LENGTH_LONG).show(); Log.e(TAG, "received unhandled action to start activity: " + intent); setResult(RESULT_CANCELED);//from w w w . java 2 s .com finish(); return; } final String type = intent.resolveType(this); final LoaderManager lm = getSupportLoaderManager(); setProgressBar(true); if (MediaProvider.TYPE_CASTMEDIA_DIR.equals(type)) { lm.initLoader(LOADER_CASTMEDIA_DIR, null, this); } else if (MediaProvider.TYPE_CASTMEDIA_ITEM.equals(type)) { lm.initLoader(LOADER_CASTMEDIA_ITEM, null, this); } setFullscreen(true); adjustForOrientation(getResources().getConfiguration()); }