Android简易Flash播放器(暂停、播放、重播)
- 格式:docx
- 大小:18.42 KB
- 文档页数:7
申明下:重播有js调用flash函数重播有问题。这个和安全沙箱有关系。我搞不定。所以这里的重播是刷新了WebView。
上一节,大体说了下在Android程序中嵌套Flash动画。这次按照上次的内容做个扩展,做个简易的flash播放器。
前提条件如上一节所说,需要Android2.2平台和安装flash的插件。
先看工程图和效果图:
工程源码:
1.package com.geolo.android.flash;
2.
3.import com.geolo.android.FileBrowser;
4.import com.geolo.android.R;
5.
6.import android.app.Activity;
7.import android.app.AlertDialog;
8.import android.app.ProgressDialog;
9.import android.content.DialogInterface;
10.import android.content.Intent;
11.import android.os.Bundle;
12.import android.os.Handler;
13.import android.os.Message;
14.import android.util.Log;
15.import android.view.KeyEvent;
16.import android.view.View;
17.import android.webkit.WebChromeClient;
18.import android.webkit.WebSettings.PluginState;
19.import android.webkit.WebView;
20.import android.widget.Button;
21.import android.widget.FrameLayout;
22.import android.widget.ProgressBar;
23.
24.public class FlashActivity extends Activity{
25.
26. private WebView mWebView;
27. private Button
playButton,pauseButton,rewindButton,exitButton,fileButton;
28. private ProgressBar mProgressBarHorizontal;
29. private final static int PROGRESSBARSIZE = 0x0000;
30. private final static int FLASH_START = 0x0001;
31. private String flashName ;
32. private boolean stopThread = false;
33. private ProgressDialog mProgressDialog;
34.
35. @Override
36. public void onCreate(Bundle savedInstanceState) {
37. super.onCreate(savedInstanceState);
38. setContentView(yout.main);
39.
40. mProgressDialog = new ProgressDialog(this);
41. mProgressDialog.setMessage("Flash动画正在加载,请稍
等......");
42. mProgressDialog.show();
43.
44. Intent intent = this.getIntent();
45. String fileName = intent.getStringExtra("fileName");
46. if(fileName != null && !fileName.equals("")){
47. flashName = "file://"+fileName;
48. //flashName =
"javascript:setFlashPath(flashName)";
49. }else{
50. flashName =
"file:///android_asset/sample/flash.swf";
51. }
52. Log.d(this.getClass().getName(),
flashName);
53.
54. mWebView = (WebView)findViewById(R.id.webView01);
55. mProgressBarHorizontal =
(ProgressBar)findViewById(R.id.progress_horizontal);
56. this.setProgress(mProgressBarHorizontal.getProgress
() * 100);
57. //this.setSecondaryProgress(mProgressBarHorizontal.
getSecondaryProgress() * 100);
58. playButton = (Button)findViewById(R.id.playButton);
59. pauseButton =
(Button)findViewById(R.id.pauseButton);
60. rewindButton =
(Button)findViewById(R.id.rewindButton);
61. exitButton = (Button)findViewById(R.id.exitButton);
62. fileButton = (Button)findViewById(R.id.fileButton);
63. playButton.setOnClickListener(buttonListener);
64. pauseButton.setOnClickListener(buttonListener);
65. rewindButton.setOnClickListener(buttonListener);