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

The following examples show how to use android.widget.VideoView#setVideoPath() . 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: VideoTrimActivity.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
private void init(String videoPath) {
    setContentView(R.layout.activity_trim);
    TextView duration = (TextView) findViewById(R.id.duration);
    mPreview = (VideoView) findViewById(R.id.preview);

    mShortVideoTrimmer = new PLShortVideoTrimmer(this, videoPath, Config.TRIM_FILE_PATH);
    mMediaFile = new PLMediaFile(videoPath);

    mSelectedEndMs = mDurationMs = mMediaFile.getDurationMs();
    duration.setText("时长: " + formatTime(mDurationMs));
    Log.i(TAG, "video duration: " + mDurationMs);

    mVideoFrameCount = mMediaFile.getVideoFrameCount(false);
    Log.i(TAG, "video frame count: " + mVideoFrameCount);

    mPreview.setVideoPath(videoPath);
    mPreview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mediaPlayer) {
            play();
        }
    });

    initVideoFrameList();
}
 
Example 2
Source File: VideoPagerFragment.java    From MediaLoader with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_media, container, false);
    mVideoView = (VideoView) rootView.findViewById(R.id.videoView);
    mVideoViewSeekBar = (VideoViewSeekBar) rootView.findViewById(R.id.mediaSeekBar);
    mVideoViewSeekBar.setVideoView(mVideoView);
    mUrl = getArguments().getString(BUNDLE_KEY_URL);

    mMediaLoader = MediaLoader.getInstance(getContext());
    mMediaLoader.addDownloadListener(mUrl, this);
    boolean isCached = mMediaLoader.isCached(mUrl);
    if (isCached) {
        mVideoViewSeekBar.setSecondaryProgress(mVideoViewSeekBar.getMax());
    }
    mVideoView.setVideoPath(mMediaLoader.getProxyUrl(mUrl));
    return rootView;
}
 
Example 3
Source File: MediaFragment.java    From MediaLoader with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_media, container, false);
    mVideoView = (VideoView) rootView.findViewById(R.id.videoView);
    mVideoViewSeekBar = (VideoViewSeekBar) rootView.findViewById(R.id.mediaSeekBar);
    mVideoViewSeekBar.setVideoView(mVideoView);
    mUrl = getArguments().getString(BUNDLE_KEY_URL);

    mMediaLoader = MediaLoader.getInstance(getContext());
    mMediaLoader.addDownloadListener(mUrl, this);
    boolean isCached = mMediaLoader.isCached(mUrl);
    if (isCached) {
        mVideoViewSeekBar.setSecondaryProgress(mVideoViewSeekBar.getMax());
    }
    mVideoView.setVideoPath(mMediaLoader.getProxyUrl(mUrl));
    mVideoViewSeekBar.start();
    return rootView;
}
 
Example 4
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 5
Source File: VideoActivity.java    From VideoCompressor with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    vvVideo= (VideoView) findViewById(R.id.vvVideo);
    geturl=getIntent().getStringExtra("vvVideo");
    vvVideo.setVideoPath(geturl);
    vvVideo.start();
}
 
Example 6
Source File: VideoPlayActivity.java    From VideoRecord with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_play);
    libPlayVideo_tv_title = (TextView) findViewById(R.id.libPlayVideo_tv_title);
    libPlayVideo_tv_title.setText("视频播放");
    videoView = (VideoView) findViewById(R.id.libPlayVideo_videoView);
    videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            if (isFirst) {
                isFirst = false;
                Toast.makeText(VideoPlayActivity.this, "播放该视频异常", Toast.LENGTH_SHORT).show();
            }
            return true;
        }
    });

    String mVideoPath = getIntent().getStringExtra(VedioRecordActivity.kVideoSavePath);
    File file = new File(mVideoPath);
    if (file.exists()) {
        videoView.setVideoPath(file.getAbsolutePath());
        videoView.start();
        setLoop(file.getAbsolutePath());
    } else {
        Log.e("tag","not found video " + mVideoPath);
    }
}
 
Example 7
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 8
Source File: MediaUtil.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the video specified by mediaPath into the given VideoView.
 *
 * Note that if the mediaPath is an asset or an URL, the video must be copied
 * to a temp file and then loaded from there. This could have performance
 * implications.
 *
 * @param videoView the VideoView
 * @param form the Form
 * @param mediaPath the path to the media
 */
public static void loadVideoView(VideoView videoView, Form form, String mediaPath)
    throws IOException {
  MediaSource mediaSource = determineMediaSource(form, mediaPath);
  switch (mediaSource) {
    case ASSET:
    case URL:
      File tempFile = cacheMediaTempFile(form, mediaPath, mediaSource);
      videoView.setVideoPath(tempFile.getAbsolutePath());
      return;

    case REPL_ASSET:
      form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      videoView.setVideoPath(replAssetPath(mediaPath));
      return;

    case SDCARD:
      form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      videoView.setVideoPath(mediaPath);
      return;

    case FILE_URL:
      if (isExternalFileUrl(mediaPath)) {
        form.assertPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
      }
      videoView.setVideoPath(fileUrlToFilePath(mediaPath));
      return;

    case CONTENT_URI:
      videoView.setVideoURI(Uri.parse(mediaPath));
      return;

    case CONTACT_URI:
      throw new IOException("Unable to load video for contact " + mediaPath + ".");
  }
  throw new IOException("Unable to load video " + mediaPath + ".");
}
 
Example 9
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	VideoView vv = (VideoView) findViewById(R.id.vv);
	vv.setVideoPath("sdcard/2.3gp");
	vv.start();
}
 
Example 10
Source File: WatchVideoActivity.java    From o2oa with GNU Affero General Public License v3.0 3 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_watch_video);

    mVv_video = (VideoView) findViewById(R.id.vv_video);

    String videoPath = getIntent().getStringExtra("video_path");

    mVv_video.setVideoPath(videoPath);
    mVv_video.start();
}