【分享】+『求助』 webview 播放不了 flash
我已经在代码里加了mWebView.getSettings().setPluginState(PluginState.ON);
但是还是不能播放flash,一片空白啊,是在真机上,不是模拟器!
browser是可以播放的,已经安装了flash 10.3 for android
接下来贴上我的代码,有需要的可以参考:
package com.WebViewTest;
import java.io.File;
import java.io.FileOutputStream;
import com.WebViewTest.R;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Picture;
public class WebViewTest extends Activity
{
private WebView mWebView;
private EditText editText;
private Button go;
private Handler mHandler;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
// WebViewFragment fragment = (WebViewFragment)getFragmentManager().findFragmentById(R.id.fragment);/*android3.0 new feature*/
// mWebView = fragment.getWebView(); /*android3.0 new feature*/
mWebView = (WebView) findViewById(R.id.webView);
editText = (EditText) findViewById(R.id.editText);
go = (Button)findViewById(R.id.go);
mHandler = new Handler();
// WebView mWebView = new WebView(this);
//setContentView(mWebView);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
// mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setEnableSmoothTransition(true); /*android3.0 new feature*/
mWebView.getSettings().setLoadsImagesAutomatically(true);
// mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
mWebView.setFocusableInTouchMode(true);
mWebView.setScrollbarFadingEnabled(false);
mWebView.setSaveEnabled(true);
WebView.enablePlatformNotifications();
registerForContextMenu(mWebView);
final Activity activity = this;
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
/* WebViewTest.this.getWindow().setFeatureInt(
Window.FEATURE_PROGRESS, progress * 100);*/
activity.setTitle("Loading...");
editText.setText(mWebView.getUrl());
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 100);
if(progress == 100){
activity.setTitle("Loading Finish!");
}
}
});
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
public void onPageFinished(WebView view, String url) {
/* mHandler.post(new Runnable() {
public void run() {
mWebView.loadUrl("javascript:showAndroidToast('hello')");
}
});*/
super.onPageFinished(view, url);
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
// Log.i("=============",""+ mWebView);
go.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!editText.getText().toString().startsWith("http://") && !editText.getText().toString().startsWith("file:///")){
mWebView.loadUrl("http://"+editText.getText().toString());
mWebView.requestFocus();
}else{
mWebView.loadUrl(editText.getText().toString());
mWebView.requestFocus();
}
}
});
mWebView.loadUrl("file:///mnt/sdcard/v.html");
}
/*@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}*/
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
/* && event.getAction() == KeyEvent.ACTION_UP */
&& editText.isFocused()) {
/*if( editText.getText().subSequence(1, 4).toString().equal("http")){
mWebView.loadUrl(editText.getText().toString());
mWebView.requestFocus();
}*/
if(!editText.getText().toString().startsWith("http://") && !editText.getText().toString().startsWith("file:///")){
mWebView.loadUrl("http://"+editText.getText().toString());
mWebView.requestFocus();
}else{
//Log.i("=========3333333=======","http ???" + editText.getText().subSequence(1, 4).toString());
mWebView.loadUrl(editText.getText().toString());
mWebView.requestFocus();
}
return true;
}
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
mWebView.goBack();
mWebView.requestFocus();
return true;
}
if (event.getKeyCode() == KeyEvent.KEYCODE_ALT_RIGHT && mWebView.canGoForward()) {
mWebView.goForward();
mWebView.requestFocus();
return true;
}
return super.dispatchKeyEvent(event);
}
// public class JavaScriptInterface {
// Context mContext;
//
// /** Instantiate the interface and set the context */
// JavaScriptInterface(Context c) {
// mContext = c;
// }
//
// /** Show a toast from the web page */
// public void showToast(String toast) {
// Log.i("=======================================","say hello is clicked");
// Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
// }
// }
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.search:
// mWebView.showFindDialog("", true);/*android3.0 new feature*/
return true;
case R.id.save:
/*String savename = mWebView.getUrl().toString();
ValueCallback<String> callback = null;
mWebView.saveWebArchive("/mnt/sdcard/Download/"+savename,true,callback);
Log.i("~~~~~~~~~~~~~callback~~~~~~~~~~~~~~","" + callback);
mWebView.loadUrl("file:///mnt/sdcard/Download/"+savename);*/
Picture pic = mWebView.capturePicture();
int width = pic.getWidth();
int height = pic.getHeight();
if (width > 0 && height > 0) {
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
pic.draw(canvas);
try {
String fileName = "sdcard/ss/" + System.currentTimeMillis() + ".png";
File outfile = new File(fileName);
Log.i("==============Create File==============",""+outfile.exists());
if(!outfile.exists()){
outfile.createNewFile();
}
else {FileOutputStream fos = new FileOutputStream(fileName);
if (fos != null) {
bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
}
Toast.makeText(getApplicationContext(), "截图成功,文件名是:" + fileName, Toast.LENGTH_SHORT).show();
}
}catch (Exception e) {
e.printStackTrace();
}
}
return true;
default:
return super.onOptionsItemSelected(item);
}
/* return false;*/
}
@Override
protected void onDestroy() {
mWebView.destroy();
super.onDestroy();
}
}
[解决办法]
和你的android版本有关吧?android2.2之前是不能支持flash
[解决办法]
帮顶一下!我也在苦恼类似的问题。据说flash Player对CPU有要求,非X86构架的只支持arm v7以上的处理器,如cortex-A8. 我的硬件无法改了,现在想通过chrome浏览器调本地的媒体播放器(如mediaPlayer)来实现网络视频的播放,不知道该如何实现。头大也!
[解决办法]
我在几个论坛都问了,没人理。感觉在我们国家对android的研发还很肤浅,只做一些皮面上的功夫,深入的人很少,大家努力啊~~!
[解决办法]
其实做过的人不少 只是肯分享经验的少罢了
------解决方案--------------------
flash Player对CPU有要求,非X86构架的只支持arm v7以上的处理器,这点道是确实存在。
[解决办法]
同学,你这个问题很大了。。。webview可以直接播放flash吗。。当然要加上flash播放器。。。
给你代码参考。。很简单的。。。
webview_main.loadUrl("file:///android_asset/sample/index.html");
<object width="300" height="200">
<param name="movie"
value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"></param>
<param name="flashvars"
value="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed
src="http://10.1.1.137:8080/testRed5.swf"
type="application/x-shockwave-flash" allowscriptaccess="always"
allowfullscreen="true" width="500" height="300"
flashvars="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv">
</embed>
</object>
[解决办法]
我调用的网络上的html,只设置了这一项webSettings.setPluginState(WebSettings.PluginState.ON);就能播放网页上的flash了,初学者,希望对楼主有帮助,呵呵
[解决办法]
你用果tomcat吗,你把你的cis_base.swf放到tomcat上面然后src="http://你的ip:8080/你的web应用/cis_base.swf"就可以了。
[解决办法]
不知道
[解决办法]
LZ问题解决了吗? 我也有类似的问题,我用的模拟器2.2的系统,代码也很少,
java 类里:
webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl("file:///android_asset/index.html");
html里:
<object width="300" height="200">
<param name="movie"
value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"></param>
<param name="flashvars"
value="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed
src="http://10.1.1.137:8080/testRed5.swf"
type="application/x-shockwave-flash" allowscriptaccess="always"
allowfullscreen="true" width="500" height="300"
flashvars="src=http%3A%2F%2Fosmf.org%2Fvideos%2Fcathy2.flv">
</embed>
</object>
同样也不行,是因为我用的模拟器?我已经安了一个播放器了,分享一下吧,谢谢了
[解决办法]
和测试手机有关系(准确说,和手机内置的浏览器有关系)。
曾经我用Nexus s访问公司网站,发现flush页不能显示。
后来换了某款HTC 发现可以
[解决办法]
我的webView要加载整个纯flash网页,再3.2的平板上,点击flash网页中的网页链接,shouldOverrideUrlLoading()方法居然没有反应,,不知道怎么回事??
还有,我在flash网页加载完成前,显示了一张启动动画,然后加载完成就去掉图片,,这样显示其他网页是没问题的,就是显示这个纯flash网页显示不出来,,郁闷啊,,
有人知道吗?
[解决办法]
对于本地的文件路径,要加上file:///的前缀来访问
最近我也在做这个,3.1的平板,10.3插件,也是有一些问题,放不出来。
在webView上调用object控件的方法无效。
打算参考10楼的方法直接把flash写在网页里写死,再试试。
[解决办法]
hai 解决了吗?我也遇到了这个问题,
[解决办法]
3.0以上,需要开启硬件加速,android:hardwareAccelerated="true"
------解决方案--------------------
播flash首先要在机子上装falsh播放器 。最近也在做webview 播放flash 我用2.2
[解决办法]
一个月上一次论坛。。。。这个怎么说呢,除非很热心的,一般的程序员都是是写自己的博客,不会花时间逛论坛的,这方面我还真没做过,帮不了你不好意思。建议你到一些牛人的博客或者控件去留言好一些,项目忙的要死,时间本来很急,一般的博主看到知道的都会回复的。。。希望你能解决问题,吃饭了,回来继续加班。。。。。
[解决办法]
系统的问题 我用2.2 2.3的都能播放 唯独用3.0以上的就不能播放,肯定是系统的问题............
[解决办法]
楼主问题解决了么? 盼联系41485179 qq
[解决办法]
最近也碰到这个问题了~~~
[解决办法]
据说 android3.0 以后的系统不支付播放flash的.swf文件了! 很悲剧
[解决办法]
据说 android3.0 以后的系统不支付播放flash的.swf文件了! 很悲剧2.2以前的版本是可以播放的。
[解决办法]
据说google把flash给砍掉了啊。。。只是据说。。。
