Android does not play flash, but when there is a flash plug-in provided by Adobe, you can use WebView to open the webpage and use the webpage to play flash. Therefore, the idea of this article is to use WebView To Play flash and use java code to control the javascript code in WebView to control the playback and progress display operations of flash. Flash plug-ins cannot be installed in systems lower than android 2.2, so you cannot use this method to play flash.
First, you need to edit a webpage that can normally play flash, and provide javascript code for corresponding operations for java code to control flash playback. This is a key issue. If there is a problem with writing this webpage, compilation will not report an error, but flash playback will not work properly.
The sample code is as follows:
Empty
| <Script type = 'text/javascript '> var total; // defines the total number of bytes of a flash video var frame_number; // defines the current number of bytes of a flash video var rate = 12; // Frame Rate // dynamically displays the current number of frames/total number of frames (progress bar) of the video to be played. function showcount () {total = movie. totalFrames (); frame_number = movie. currentFrame (); frame_number ++; var progressSize = 500 * (frame_number/total); CallJava. consoleFlashProgress (progressSize, total/12);} // Play the video function Play () {movie. play (); showcount () ;}// Pause the function Pause () {m Ovie. stopPlay ();} // starts loading the function loadSWF (fsrc, fwidth, fheight) {movie. loadMovie (0, fsrc); movie. width = fwidth; movie. height = fheight; frame_number = movie. currentFrame ();} // return function GoToFrame (progress) {total = movie. totalFrames (); if (movie. isPlaying () Pause (); frame_number = total * progress/500; movie. gotoFrame (frame_number); Play () ;}// function error () {document. body. style. backgroun DImage = "url(flash_view_back_7490.jpg)"; document. getElementById ("flash_page"). innerHTML = "" + "plug-in supporting flash playback is missing. Please install and try again! ";}// Set the high function setHeight (height) {movie of flash. height = height; document. getElementById ("flash_page "). style. height = height ;}</script> |
In the above Code, javascript is used to control flash playback. For more operations, see the blog "JS controls the playback of Flash videos on webpages (with parameters)". CallJava in the code is used to reverse control the display in the java code. Java code provides corresponding methods for this class. The Code is as follows:
private final class CallJava{public void consoleFlashProgress(float progressSize, int total){showFlashProgress(progressSize, total);}}
To use the CallJava class, you also need to set WebView attributes:
flash_view.addJavascriptInterface(new CallJava(), "CallJava");
In addition, WebView can be set to call javascript and other attributes using java:
flash_view.getSettings().setJavaScriptEnabled(true); flash_view.getSettings().setPluginState(PluginState.ON);flash_view.setWebChromeClient(new WebChromeClient()); flash_view.getSettings().setAllowFileAccess(true);flash_view.getSettings().setPluginsEnabled(true);flash_view.getSettings().setSupportZoom(true);flash_view.getSettings().setAppCacheEnabled(true);
Then you can use java to control flash playback:
public void start(){if(null != flashPath){flash_view.loadUrl("javascript:loadSWF(\""+flashPath+"\", \"" + width + "\", \"" + (height-bottom_height) + "\")");flash_view.loadUrl("javascript:Play()");handler.post(update_progress);play.setImageResource(R.drawable.pause);playing = true;}show();}public void pause(){if(null != flashPath){flash_view.loadUrl("javascript:Pause()");handler.removeCallbacks(update_progress);play.setImageResource(R.drawable.play);playing = false;}}
In general, do you think it is very simple? Try it now!
Android playback flash example source code: http://download.csdn.net/detail/iloveyoueveryday/6911903.