是否可以通过网址播放视频?有很多问题要求相同,但几乎所有问题都来自5年前。想知道是否有任何改变。
答案 0 :(得分:0)
MediaController mediaController = new MediaController(getActivity());
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
Uri video = Uri.parse("your mp4 source");
videoView.setVideoURI(video);
videoView.start();
答案 1 :(得分:0)
private void playVideoFile() throws Throwable
{
try
{
MediaController m_mc = new MediaController(this);
m_mc.setAnchorView(m_vwVideoPlayerView);
m_mc.setMediaPlayer(m_vwVideoPlayerView);
m_vwVideoPlayerView.setMediaController(m_mc);
m_vwVideoPlayerView.setVideoPath("Your video url");
m_vwVideoPlayerView.requestFocus();
m_vwVideoPlayerView.start();
}
catch (Throwable e)
{
if (m_vwVideoPlayerView != null) {
m_vwVideoPlayerView.stopPlayback();
}
}
}
您还可以将听众设置为视频播放器视图
m_vwVideoPlayerView.setOnPreparedListener(new OnPreparedListener(){
public void onPrepared(MediaPlayer p_arg0)
{
if (!isFinishing()&& m_vwVideoPlayerView != null)
{
m_vwVideoPlayerView.start();
}
}
});
m_vwVideoPlayerView.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
finish();
}
});
m_vwVideoPlayerView.setOnErrorListener(new MediaPlayer.OnErrorListener(){
@Override
public boolean onError(MediaPlayer p_mp, final int p_what, final int p_extra)
{
// Display Message whcih you want to display
}
});
答案 2 :(得分:0)
MediaController mc = new MediaController(this);
mc.setAnchorView(video);
mc.setMediaPlayer(video);
url = url.replace(" ", "%20");
Log.e("url",url);
Uri videoLInk = Uri.parse(url);
video.setMediaController(mc);
video.setVideoURI(videoLInk);
video.requestFocus();
video.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
pDialog.dismiss();
video.start();
}
});
您可以传递任何视频网址。 注意:我已将%20替换为空格,因为如果您运行3G,那么您的视频将无法播放。因此,每当空间存在时,您需要先用%20 替换它。
希望它对你有所帮助。
答案 3 :(得分:0)
@Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.videodisplay);
String link="http://s1133.photobucket.com/albums/m590/Anniebabycupcakez/?action=view& current=1376992942447_242.mp4";
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}