WebView 无法在 Android 上播放 swf 文件
我正在为 android 3.0 平板电脑开发一个应用程序,它应该在 WebView 中播放 swf 文件。 首先,我尝试从设备打开 swf 文件,而不是通过互联网,但没有成功。 WebView 出现了,但在 WebView 内部我只能看到黑屏(右侧有一条 3-4 px 宽的白线)。 如果我将相同的 URL 加载到设备浏览器,则 Flash 文件可以正常播放。 我认为我在 WebView 设置中遗漏了一些东西,但经过几个小时的搜索和谷歌搜索后我仍然不知道是什么。
Java 代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.presentation);
presentationWebView = (WebView) findViewById(R.id.presentation_webview);
presentationWebView.getSettings().setJavaScriptEnabled(true);
presentationWebView.getSettings().setPluginsEnabled(true);
presentationWebView.getSettings().setAllowFileAccess(true);
presentationWebView.loadUrl("http://my_domain/fileName.swf");
}
presentation.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id = "@+id/presentation_webview"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"/>
</LinearLayout>
非常感谢您的回答。 里皮蒂翁
I am developing an application for android 3.0 tablet, that's supposed to play swf files inside a WebView.
First I tried to open the swf file from the device, than through the internet, with no luck.
The WebView shows up, but inside the WebView all I can see is a black screen (with a 3-4 px wide white line on the right).
If I load the same URL to the device browser, the flash file plays well.
I think Im missing something on the WebView setup, but after a few hours of searching and googling I still dont know what.
The Java code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.presentation);
presentationWebView = (WebView) findViewById(R.id.presentation_webview);
presentationWebView.getSettings().setJavaScriptEnabled(true);
presentationWebView.getSettings().setPluginsEnabled(true);
presentationWebView.getSettings().setAllowFileAccess(true);
presentationWebView.loadUrl("http://my_domain/fileName.swf");
}
The presentation.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id = "@+id/presentation_webview"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"/>
</LinearLayout>
Thank you very mouch for any answers.
Ripityom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于拿到了!
只需将该属性添加
到我的清单文件中即可。
I've got it finally!
Only needed to add the attribute
to my manifest file.
我只是将您的代码复制并粘贴到一个新项目中,更改了 swf 文件位置,并且它运行良好。 (在 .swf 文件下载完成之前,屏幕会显示空白,这在某些情况下可能需要一段时间)。
您的应用程序有 INTERNET 权限吗?网址绝对正确吗?尝试使用几个不同的 SWF 文件,看看是否有差异。
I just copy&pasted your code into a new project, changed the swf file location, and it worked perfectly. (The screen is blank until the .swf file finishes downloading, which can take a while in some cases).
Does your app have the INTERNET permission? The URL is definitely correct? Try with a couple of different SWF files and see if there's a difference.
谢谢皮皮蒂姆。属性“android:hardwareAccelerated”救了我的命。也为我工作。
这里我贴出android开发者文档中的解释“从Android 3.0开始,应用程序可以使用硬件加速的OpenGL渲染器,以提高许多常见2D图形操作的性能。当启用硬件加速渲染器时,大多数操作都在Canvas中进行, Paint、Xfermode、ColorFilter、Shader 和 Camera 均得到加速,从而实现更流畅的动画、更流畅的滚动以及整体改进的响应能力,即使对于未明确使用该框架的 OpenGL 库的应用程序也是如此。
请注意,并非所有 OpenGL 2D 操作都会加速。如果启用硬件加速渲染器,请测试您的应用程序以确保它可以毫无错误地使用渲染器。”
Thx Pipityom. The attribute "android:hardwareAccelerated" save my life. Work for me as well.
Here I post the explanation from android developer document "Starting from Android 3.0, a hardware-accelerated OpenGL renderer is available to applications, to improve performance for many common 2D graphics operations. When the hardware-accelerated renderer is enabled, most operations in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated. This results in smoother animations, smoother scrolling, and improved responsiveness overall, even for applications that do not explicitly make use the framework's OpenGL libraries.
Note that not all of the OpenGL 2D operations are accelerated. If you enable the hardware-accelerated renderer, test your application to ensure that it can make use of the renderer without errors."