【问题标题】:How to show video in android from google drive url如何从谷歌驱动器 url 在 android 中显示视频
【发布时间】:2014-07-15 08:11:45
【问题描述】:

我想在 android 应用程序中显示视频。我在谷歌上搜索并找到下面的代码

VideoView videoView = (VideoView) findViewById(R.id.videoView);

String vidAddress = "https://docs.google.com/a/user.co.jp/file/d/something..privatecookie/preview";

Uri videoUri = Uri.parse(vidAddress);

MediaController mediaController = new MediaController(this); mediaController.setAnchorView(videoView); videoView.setMediaController(mediaController);

videoView.setVideoURI(videoUri); videoView.start();

我已经把上面的代码放在activity的onCreate方法中了。

当我运行应用程序时出现错误“抱歉,无法播放此视频。”

日志显示如下

07-15 13:58:13.110: V/MediaPlayer-JNI(19546): native_setup
07-15 13:58:13.110: V/MediaPlayer(19546): constructor
07-15 13:58:13.125: V/MediaPlayer(19546): setListener
07-15 13:58:13.125: I/MediaPlayer(19546): path is null
07-15 13:58:13.125: D/MediaPlayer(19546): Couldn't open file on client side, trying server side
07-15 13:58:13.140: V/MediaPlayer(19546): setVideoSurfaceTexture
07-15 13:58:13.140: V/MediaPlayer-JNI(19546): setAudioStreamType: 3
07-15 13:58:13.140: V/MediaPlayer(19546): MediaPlayer::setAudioStreamType
07-15 13:58:13.140: V/MediaPlayer(19546): setVideoSurfaceTexture
07-15 13:58:13.140: V/MediaPlayer(19546): prepareAsync
07-15 13:58:16.810: V/MediaPlayer(19546): message received msg=100, ext1=1, ext2=-2147483648
07-15 13:58:16.810: E/MediaPlayer(19546): error (1, -2147483648)
07-15 13:58:16.810: V/MediaPlayer(19546): callback application
07-15 13:58:16.810: V/MediaPlayer(19546): back from callback
07-15 13:58:16.815: E/MediaPlayer(19546): Error (1,-2147483648)
07-15 13:58:16.815: D/VideoView(19546): Error: 1,-2147483648

我可以在浏览器上看到视频。

上传的视频文件类型为mpg、mp4和wmv

如果有人有解决方案,请帮忙。

谢谢

编辑:经过一些工作,我知道其中一个原因是 Android 版本 4.0.3。上面提到的代码适用于示例网址,例如 http://download.itcuties.com/teaser/itcuties-teaser-480.mp4 仅在 4.2.2 中。 来自 Google 文档 url 的视频仍然无法正常工作。我应该怎么做才能在 4.0.3 上玩它

【问题讨论】:

  • 尝试使用exoplayer并在exoplayer中播放视频可能会奏效。
  • @bhaveshkaila 您好,Bhavesh 先生,我尝试使用 exoplayer。在客户公司,他们使用的是 android 4.0.3。由于 4.0.3 中没有 exoplayer 核心类,我将 lib 更改为 4.2.2,但是在 4.0.3 移动设备上运行时,它会给出 java.lang.verifyerror
  • @bhaveshkaila 您好,Bhavesh 先生,我尝试在具有 4.2.2 的手机上使用上述代码播放一些 mp4 视频,并且运行良好但无法在 4.0.3 上播放,这可能是什么原因?根据文件 3.0+ 支持 .mp4 -- Piyush Merja
  • 关注这个[使用 ](stackoverflow.com/questions/29596614/…) 播放 google drive 视频
  • 这个答案在 2019 年似乎是最好的:stackoverflow.com/questions/52892844/…

标签: android google-drive-api


【解决方案1】:

您解析为 Uri 的 url 与 VideoView 不兼容,因为它只是一个用于在 html 中嵌入 iframe 的 web url。请按照此here 进行解决。

【讨论】:

    【解决方案2】:

    据我所知,这似乎是一个常见问题。请参阅thisthis

    所以问题很可能是您的视频格式不正确(基线 H.264)。尝试找到具有这种格式的视频或转换您的视频,您的代码应该可以工作。

    【讨论】:

      【解决方案3】:

      你可以使用网页视图

      String frameVideo = "<html><body>Video From YouTube<br><iframe width=\"420\" 
      height=\"315\"  src=\"https://drive.google.com/file/d/VIDEO_ID/preview\" 
          frameborder=\"0\" allowfullscreen></iframe></body></html>";
      
          WebView myWebView = (WebView) findViewById(R.id.mWebView);
      
          WebSettings webSettings = myWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          myWebView.loadData(frameVideo, "text/html", "utf-8");
      

      【讨论】:

        猜你喜欢
        • 2014-10-18
        • 1970-01-01
        • 1970-01-01
        • 2022-08-18
        • 1970-01-01
        • 1970-01-01
        • 2019-01-06
        • 2021-12-16
        • 1970-01-01
        相关资源
        最近更新 更多