43

我是 android 开发的初学者,并尝试从链接播放视频。但它给出了错误"sorry,we can't play this video"。我尝试了很多链接,但所有链接都显示相同的错误。

我的代码如下

public class VideoDemo extends Activity {

        private static final String path ="http://demo.digi-corp.com/S2LWebservice/Resources/SampleVideo.mp4";
 private VideoView video;
 private MediaController ctlr;
 @Override
 public void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            getWindow().setFormat(PixelFormat.TRANSLUCENT);
            setContentView(R.layout.videoview);

            video = (VideoView) findViewById(R.id.video);
            video.setVideoPath(path);

            ctlr = new MediaController(this);
            ctlr.setMediaPlayer(video);
            video.setMediaController(ctlr);
            video.requestFocus();
     }
}

Logcat 显示以下错误消息:

04-12 15:04:54.245: ERROR/PlayerDriver(554): HandleErrorEvent: PVMFErrTimeout
4

9 回答 9

47

它与您的链接和内容有关。尝试以下两个链接:

    String path="http://www.ted.com/talks/download/video/8584/talk/761";
    String path1="http://commonsware.com/misc/test2.3gp";

    Uri uri=Uri.parse(path1);

    VideoView video=(VideoView)findViewById(R.id.VideoView01);
    video.setVideoURI(uri);
    video.start();

从“path1”开始,它是一个轻量级的小视频流,然后尝试“path”,它比“path1”分辨率更高,完美的手机分辨率。

于 2010-04-17T17:36:11.607 回答
8

尝试这个:

String LINK = "type_here_the_link";
setContentView(R.layout.mediaplayer);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse(LINK);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
于 2010-04-16T12:04:25.457 回答
6
pDialog = new ProgressDialog(this);

    // Set progressbar message
    pDialog.setMessage("Buffering...");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    // Show progressbar
    pDialog.show();

    try {
        // Start the MediaController
        MediaController mediacontroller = new MediaController(this);
        mediacontroller.setAnchorView(mVideoView);      

        Uri videoUri = Uri.parse(videoUrl);
        mVideoView.setMediaController(mediacontroller);
        mVideoView.setVideoURI(videoUri);

    } catch (Exception e) {

        e.printStackTrace();
    }

    mVideoView.requestFocus();
    mVideoView.setOnPreparedListener(new OnPreparedListener() {
        // Close the progress bar and play the video
        public void onPrepared(MediaPlayer mp) {
            pDialog.dismiss();
            mVideoView.start();
        }
    });
    mVideoView.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {
            if (pDialog.isShowing()) {
                pDialog.dismiss();
            }
            finish();               
        }
    });
于 2014-08-27T11:20:32.453 回答
5

你可以使用FullscreenVideoView类来做到这一点。它是一个小型图书馆项目。它的视频进度对话框是内置的。它的 gradle 是:

compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.0'

你的 VideoView xml 是这样的

<com.github.rtoshiro.view.video.FullscreenVideoLayout
        android:id="@+id/videoview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

在您的活动中,使用以下方式对其进行初始化:

    FullscreenVideoLayout videoLayout;

videoLayout = (FullscreenVideoLayout) findViewById(R.id.videoview);
        videoLayout.setActivity(this);

        Uri videoUri = Uri.parse("YOUR_VIDEO_URL");
        try {
            videoLayout.setVideoURI(videoUri);

        } catch (IOException e) {
            e.printStackTrace();
        }

而已。快乐编码:)

如果想了解更多,请访问这里

编辑: gradle 路径已更新。现在编译

compile 'com.github.rtoshiro.fullscreenvideoview:fullscreenvideoview:1.1.2'
于 2016-03-30T07:09:28.923 回答
4

试试 Exoplayer2

https://github.com/google/ExoPlayer

它是高度可定制的

    private void initializePlayer() {
         player = ExoPlayerFactory.newSimpleInstance(
             new DefaultRenderersFactory(this),
             new DefaultTrackSelector(), new DefaultLoadControl());

         playerView.setPlayer(player);

         player.setPlayWhenReady(playWhenReady);
         player.seekTo(currentWindow, playbackPosition);

Uri uri = Uri.parse(getString(R.string.media_url_mp3));
     MediaSource mediaSource = buildMediaSource(uri);
     player.prepare(mediaSource, true, false);
    }

private MediaSource buildMediaSource(Uri uri) {
  return new ExtractorMediaSource.Factory(
      new DefaultHttpDataSourceFactory("exoplayer-codelab")).
      createMediaSource(uri);
}

@Override
public void onStart() {
 super.onStart();
 if (Util.SDK_INT > 23) {
   initializePlayer();
 }
}

查看此网址了解更多详情

https://codelabs.developers.google.com/codelabs/exoplayer-intro/#2

于 2018-10-22T01:49:29.690 回答
1

我也被这个问题困住了。我得到了服务器的正确响应,但无法播放视频。很长一段时间后,我在这里找到了解决方案。也许,将来此链接将无效。所以,这是我的正确代码

    Uri video = Uri.parse("Your link should be in this place "); 
    mVideoView.setVideoURI(video); 

   mVideoView.setZOrderOnTop(true); //Very important line, add it to Your code
    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
        @Override 
        public void onPrepared(MediaPlayer mediaPlayer) {
  // here write another part of code, which provides starting the video
  }}
于 2017-12-16T21:14:29.337 回答
1

请检查此链接:http: //developer.android.com/guide/appendix/media-formats.html

videoview不支持某些编解码器

我建议你使用媒体播放器,当得到“对不起,无法播放视频”时

于 2016-01-23T10:46:11.347 回答
0

使用控制器检查这个UniversalVideoView库是否简单直接。

这是播放视频的代码
在 build.gradle 中添加此依赖项

 implementation 'com.linsea:universalvideoview:1.1.0@aar'

Java 代码

        UniversalVideoView mVideoView = findViewById(R.id.videoView);
        Uri uri=Uri.parse("https://firebasestorage.googleapis.com/v0/b/contactform-d9534.appspot.com/o/Vexento%20-%20Masked%20Heroes.mp4?alt=media&token=74c2e448-5b1b-47b7-b761-66409bcfbf56");
        mVideoView.setVideoURI(uri);
        UniversalMediaController mMediaController = findViewById(R.id.media_controller);
        mVideoView.setMediaController(mMediaController);
        mVideoView.start();   

xml代码

<FrameLayout
            android:id="@+id/video_layout"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/black">

            <com.universalvideoview.UniversalVideoView
                android:id="@+id/videoView"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                app:uvv_autoRotation="true"
                app:uvv_fitXY="false" />

            <com.universalvideoview.UniversalMediaController
                android:id="@+id/media_controller"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                app:uvv_scalable="true" />

        </FrameLayout>
于 2020-03-29T12:45:42.270 回答
-1

检查您的手机是否支持视频格式。即使我在播放 3gp 文件时也遇到问题,但它可以完美播放 mp4 文件。

于 2016-06-01T07:46:32.233 回答