在VideoView中从Internet下载视频

时间:2014-03-07 07:58:28

标签: android android-videoview

请告诉我。我有一个视频链接。我有一个VideoView。他播放一些视频格式。如何将视频从Internet播放到其他格式?怎么解码呢?或者还有其他方法吗?

package com.example.MyVideo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

public class MyActivity extends Activity implements View.OnClickListener {
    /**
     * Called when the activity is first created.
     */
    private Button btn;
    private VideoView vv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn = (Button) findViewById(R.id.button);
        btn.setOnClickListener(this);
        vv = (VideoView) findViewById(R.id.videoView);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button:
                vv.setVideoURI(link);
                break;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果您想直接在videoview中查看网址,请按以下方式使用:

 VideoView mVideoView;
 MediaController mcon;
 String videourl="http://ww.abc.com/a";
 mVideoView = (VideoView) findViewById(R.id.videoview);
 mVideoView.setVideoURI(Uri.parse(videourl));
 mVideoView.start();

如果您想从网址下载视频并保存在SD卡中,请更好地使用webview
WeViewClient处理网址。参见本教程

http://androidtrainningcenter.blogspot.in/2013/11/download-file-videoaudiotext-through.html