xamarin android webview:视频无法在设备上播放

时间:2015-04-21 12:58:51

标签: android video webview xamarin xamarin.forms

尝试播放视频,我现在正在使用Xamarin.Forms XAML中的WebView。

我在Android上遇到很多问题(这是一个表单项目,它也可以在iOS和WinPhone上运行),主要是播放本地文件。

为了获得最小的失败版本,我发现即使从网络上播放视频也无效。哦,它(有点 - 至少我得到音频)在模拟器中工作,但不在我的设备上,这是三星Note 1.

我正在做的是

var htmlSource = new HtmlWebViewSource();
html = "<!Doctype HTML><html><body><video controls>   <source src=\"http://techslides.com/demos/sample-videos/small.webm\" type=\"video/webm\">   <source src=\"http://techslides.com/demos/sample-videos/small.ogv\" type=\"video/ogg\">   <source src=\"http://techslides.com/demos/sample-videos/small.mp4\" type=\"video/mp4\">  <source src=\"http://techslides.com/demos/sample-videos/small.3gp\" type=\"video/3gp\"></video></body></html>";
htmlSource.Html = html;
myWebView.Source = htmlSource; 

直接从http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5复制html(仅格式化&#34;&#34;添加)。

在AndroidManifest.xml中我添加了

android:hardwareAccelerated="true"

<manifest />

(我也试过 false 。)

我在Android设备上看到的内容:

网站打开,显示视频控件(虽然只在非常小的区域,它有一个占位符背景)。单击播放,我得到一个&#34; handleMessage - PLAY&#34;在调试器中,但没有任何反应。此外,单击全屏图标,我得到一个&#34; enterFullScreenVideoState调用。&#34;在调试器中,但没有任何反应。

其他: 直接在Android浏览器中打开http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5即可(我没有预览视频,但是当我点击播放时会加载),但设置

myWebView.Source = "http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5";

也会产生与我明确设置HtmlWebViewSource时相同的不良行为。

App拥有INTERNET权限。

有什么问题,如何解决?

(我知道在stackoverflow上有很多线程,但很多都是3 - 5年,没有一个适用于Xamarin,至少不是我迄今为止看到的。)

1 个答案:

答案 0 :(得分:1)

如果您想在本机播放器中播放视频而不是启动WebView,则可以查看Xamarin组件商店中的视频播放器组件。它允许您在iOS,Android和Windows Phone上呈现本机视频播放器。下面的代码片段显示了将其放入并使用它的最简单示例。您还可以连接诸如播放,暂停,停止,完成等事件。您可以控制音量,自动播放和重复等。

https://github.com/adamfisher/Xamarin.Forms.VideoPlayer

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:o="clr-namespace:Octane.Xam.VideoPlayer;assembly=Octane.Xam.VideoPlayer"
             x:Class="VideoPlayerSamples.VideoPlayerBasicExamplePage"
             Title="Basic Video Player">

    <o:VideoPlayer Source="http://vjs.zencdn.net/v/oceans.mp4" />

</ContentPage>

免责声明:这是我的组件。

相关问题