Android videoview-可在模拟器上使用,但不能在实际设备上使用

时间:2018-07-06 02:30:57

标签: android android-videoview

我有一个recyclerview,项目包括来自URL的videoview加载视频。在模拟器中,它运行良好。 here

但是在设备中,它不会加载视频not load video

onBindViewHolder在我的适配器中:

public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
    VideoModel item = VideoList.get(position);
    ((VHItem) holder).tvTittle.setText(item.getVideoTittle());
    ((VHItem) holder).tvTime.setText(item.getVideoTime());
    /***get clicked view and play video url at this position**/
    try {
        //play video using android api, when video view is clicked.
        String url = item.getVideoUrl(); // your URL here
        Uri videoUri = Uri.parse(url);
        ((VHItem) holder).videoView.setVideoURI(videoUri);
        //((VHItem) holder).videoView.seekTo(10);
        ((VHItem) holder).videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {

                mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                    @Override
                    public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

                        /*
                         * add media controller
                         */

                        MediaController mc = new MediaController(mContext);
                        mc.setMediaPlayer(((VHItem) holder).videoView);
                        ((VHItem) holder).videoView.setMediaController(mc);
                        /*
                         * and set its position on screen
                         */
                        mc.setAnchorView(((VHItem) holder).videoView);
                    }
                });
                ((VHItem) holder).videoView.seekTo(10);
            }
        });


    } catch (
            Exception e)

    {
        e.printStackTrace();
    }

}

并且列表中包含视频的网址:

listVideo = new ArrayList<>();
    listVideo.add(new VideoModel(1,"BẠC LIÊU ĐẤT & NGƯỜI\n" +
            "Bạc Liêu hôm nay",
            "",
            "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4",
            "Thứ Sáu, 29/06/2018, 08:20"));
    listVideo.add(new VideoModel(2,"BẠC LIÊU ĐẤT & NGƯỜI\n" +
            "Bạc Liêu quê hương tôi",
            "",
            "http://video.baobaclieu.vn/uploads/video/2017/05/11/N%C3%B4ng%20d%C3%A2n%20B%E1%BA%A1c%20Li%C3%AAu%20tr%C3%BAng%20m%C3%B9a%20gi%E1%BB%AFa%20c%C6%A1n%20%C4%91%E1%BA%A1i%20h%E1%BA%A1n%20-%20VTC.mp4",
            "Thứ Tư, 27/06/2018, 13:25"));

有人知道这个实际可行的常见问题的解决方案吗? 谢谢!

0 个答案:

没有答案