我最近想实现一个功能,是在文章中嵌入一个视频播放的功能。效果如图。
就是点击之后全屏播放。视频是在线视频,视频源来自腾讯,优酷,也有百度云的源文件。
现在是看过了vitamio开源库,因为导入后太大了,所以打算放弃。
videoview好像是可以播放网络视频的,但是我试了一下并没有成功,不清楚具体原因是什么。。是视频源的问题吗?
贴一下代码
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri uri = Uri.parse("http://v.qq.com/x/cover/c4d0gfkiguexa9h/q0328qbk05q.html");
VideoView videoView = (VideoView) findViewById(R.id.videoView);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
}
网络权限已经添加了。
在这里诚心向各位请教这个问题,或有介绍视频播放的文章,或有轻量级的开源库,或者有过开发经验的,希望各位能指导一下。
Your video address is incorrect. To play the video in VideoView, you should give it a video address similar to "http://.mp4". You can't play it directly by putting it on a web page. Also, if your video is a live video such as RTMP or m3u8, the native VideoView cannot play it. You need to use a third-party library such as ijkPlayer or write your own parsing (not recommended).