【问题标题】:VideoView not playing in Android ApplicationVideoView 未在 Android 应用程序中播放
【发布时间】:2016-11-12 16:30:29
【问题描述】:

场景

我有一个使用主/细节布局的 Android 应用。 因此,当我单击左侧面板中的“视频”时,它会导航到下载视频名称和链接的新面板。然后选择标题后,左侧面板隐藏并且视频开始播放。

问题

我使用了 videoview,但奇怪的是,我无法播放视频。我并没有真正收到错误,但是屏幕仍然是黑色的,我相信我听到了视频前几秒的声音,然后是我上传的图像,但没有图像。

查看代码

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.fragment_drone_life3, null);
    vidView=(VideoView)view.findViewById(R.id.ivEvent);
    context=this.getActivity();
    return view;
}
 public void onItemClick(AdapterView<?> adapterView, View view,
                                    int position, long id) {
                if (new ConnectionDetector(context).isConnectingToInternet()) {
//get VidLink variable of item in this location and place in the var videoLink
                    videoLink = eventsDTOs.get(position).getVidLink();

                    try {

                        MediaController mediaController = new MediaController(getContext());
                        mediaController.setAnchorView(vidView);
                        Uri video = Uri.parse(videoLink);
                        vidView.setMediaController(mediaController);
                        vidView.setVideoURI(video);
                        vidView.start();
                        MainActivity.closeSlidingDrawer();
                    } catch (Exception e) {
                        // TODO: handle exception
                         Toast.makeText(getContext(), "Error connecting", Toast.LENGTH_SHORT).show();
                    }


                   // new TaskGetEventImage().execute(eventsDTOs.get(position).getId());
                } else {
                    Toast.makeText(context, context.getResources().getString(R.string.NETWORK_ERROR),Toast.LENGTH_LONG).show();
                }
            }

【问题讨论】:

    标签: android video android-videoview


    【解决方案1】:

    用于从 URL 播放视频

       VideoView videoView=(VideoView) findViewById(R.id.myVideo);
       videoView.setVideoURI(Uri.parse("http://website.com/somevideoname.mp4"));
       videoView.setMediaController(new MediaController(this));
       videoView.requestFocus();
       videoView.start();
    

    用于播放 SD 卡或内部存储中的视频

        MediaController vidControl;
        String sdPath;
    
        VideoView videoView=(VideoView) findViewById(R.id.myVideo);
        vidControl = new MediaController(this);
        vidControl.setAnchorView(videoView);
        videoView.setMediaController(vidControl);
        videoView.setVideoPath(sdPath);
        videoView.requestFocus();
        videoView.start();
    

    我会建议尝试使用上述解决方案来播放视频。

    【讨论】:

    • 抱歉不是解决方案,只是不正确的复制和粘贴
    • 检查已编辑的解决方案,该解决方案不适用于模拟器。你应该使用真正的手机。我希望它会工作
    【解决方案2】:

    解决了这个问题,显然错误是我的服务器做了一些手机无法处理的编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 2014-01-03
      • 2015-07-15
      相关资源
      最近更新 更多