Android:从下载网址播放视频

时间:2014-07-18 10:49:39

标签: android

我知道VideoView可以播放给定的流URL。但是可以播放来自下载URL的视频吗?

2 个答案:

答案 0 :(得分:1)

它可以是其他选项,在默认播放器中播放视频

  String extension = MimeTypeMap.getFileExtensionFromUrl("video url");          
  String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
  Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
  mediaIntent.setDataAndType(Uri.parse("video url"), mimeType);
  startActivity(mediaIntent);

答案 1 :(得分:0)

public class HomeActivity extends Activity {
    String url = "Type your url here ";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
         VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
           myVideoView.setVideoURI(Uri.parse(url));
           myVideoView.setMediaController(new MediaController(this));
           myVideoView.requestFocus();

           myVideoView.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

}