Hey, the first time I wrote the article, it is very nervous, this is the result of checking data on the Internet a few days ago, I hope to be useful to some friends. The horizontal limit, there is definitely wrong, the drums and high-end fingers are very grateful! Below, the book is positively transmitted: Flash has a classmate with JavaScript for intermediary and ASP / PHP, and the popularity is more popular. The previous time administrator trust me to write a HTML-based player on the class message, as required, it is to realize loop playback. So I wrote one, it is easier, nothing more than JavaScript operation and the interaction of the ActiveX control, checks MSDN to decide to use WMP's ActiveX plugin. After writing, the playback effect is always unreasonable. I don't know if I wrote JavaScript or WMP's JavaScript interface. There is a problem. Sometimes it is sometimes possible when playing. Later, I thought that Flash 7.0 can also play MP3, so I started design (I didn't learn system engineering so I didn't standard, I wouldn't laugh at generous): Goal: 1. Play MP3, basic play control function (pause, continue, index , Volume control, etc.); 2. Current track loop, list track loop implementation: 1. Musical list Dynamic retrieval from the database 2. Provide interface to add music URL here, my idea is: User Access ASP (PHP) page => ASP (PHP) Request Database => Return Data Set => ASP (PHP) Courses Data to JavaScript Variable => JavaScrit Write the DynamicText variable in Flash by flash interface => Flash will display this. One problem, the number of file list is unprepared, how to handle it in Flash, set a few variables? My solution is (maybe not a good way, but it is very simple. If the master has a better way, please let me know, thank you): Set two variables in Flash, one is saved file name varsongname another It is saved URL VARURL.
In the Server end, it is generated as (the English quotation marks herein is automatically replaced with Chinese quotation marks, please note): var strsongname = "SongName1, SongName2, SongName3"; variable definition / assignment statement of client JavaScript, then use The setvariable () statement incorporates this variable into the flash, Flash will set string split () into an array, then, don't teach it? Everyone is displayed. Under such ideas, 3 files have been born (SFMP means Simple Flash MP3 Player) 1) sfmp.swf - Flash file as a user interface; 2) sfmp.asp (.php) - request The database uses the file list as the HTML file returned by the Tarrable variable of JavaScript; 3) add.asp (.php) Add URL page. The procedure logic of each file is specifically explained, and the work step: sfmp.swf production
Since Flash MX 2004 Professional is used, many components are borrowed directly. (However, it should be cautious, because once the ActionScript 2.0 and the components are added, the file will increase, which will generally be more than 60 KB, depending on the use of the components. Specific reasons may include many set libraries?) Here is the components used inside: MediaPlayback Components: You can play MP3 directly. It includes many properties and methods, events. There is a more detailed description in Macromedia. InstanceName: _Player Action:
On (LOAD) {// You can insert some player initialization code} ON (Complete) {// This event generates // switching process if a music is played, resulting == true) {//// When a loop playing current track _Root._Player.Play ();} else {if (_root._cbloopall.selected == true) {// Select a loop play all list track var IindexRead: Number = _root.sonslist.selectedIndex; // Move a high bright strip in the list // If you have already arrived, reset the IIndexread ; if (IINDEXREAD> _ROOT.SONGSLIST.LENGTH - 1) {// set current Song index = 0 = 0 @ iDexread = 0;} // Update list display _root.songslist.selected "ot.songslist.selected; // Here, a function is called to get the playlist's currently selected URL / / and use setMedia () and play () methods to play the player play track // Due to the relatively simple }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} {// is playing music}}} {// When downloading music files} List component: The list of files used to retrieve from the database. InstanceName: SongSlist Action:
On (Change) {// Player Control // Get List Item Data Var Str: String = this.getItemt (this.selectedIndIndex) .data; if (str.Length> 0 && str! = undefined) {// Open THE URL _Root._Player.SetMedia (Str, "MP3"); if (_root._player.contentpath.length> 0) {_root._player.play ();}}} / * read the currently selected file from the list, get Its DATA (assuming that the required information has been read from the database, the Label display file name DATA is stored in the file URL) Since set the MediaPlayback component to AutoStart = FALSE, you need to run the play () method to start playing if AutoStart = True, once the ContentPath property is set, immediately load and play * / checkbox components: There are two, used to choose a single loop or a list loop. InstanceName: _cbloopCur, _cbloopall action: The two are mutually exclusive relationships, select one, cancel the other, two are not selected, the playback selection track is over, the code is simple, slightly. Dynamic Text Box: There are two, although not a component, but is the key to interacting with JavaScript. Variable: VarsongName, VARURL two variables are filenames and URLs that save the outside world, respectively. Tips: In JavaScript, Flash provides a lot of interface functions, which is used to set the setvariable (variable_name, value) function of the variable in Flash; Flash, a ActionScript function fscommand () is also provided with JavaScript interaction.
Sfmp.asp (PHP) file program logic: This program is very simple, I will not talk, directly post the code, if you don't understand, you can ask me, email contact.
<% 'This is some source code for sfmp.asp. After some modifications, it may contain some errors, because there is no test' Some environments may be different from the above machine, please modify accordingly.
'The complete source code before modifying is the test of the Windows98 PWS Access environment', so please check if there is no spelling or other obvious mistakes before use, thank you! Option Explicit Dim Rsfiles, CNN, STRSQL, STRCNN 'Using the ADO link database, obtains the data set, and there is no good speaking strCNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN.4.0; Data Source = "& Server.mappath (" Songs. mdb ") Set cnn = Server.CreateObject (" ADODB.Connection ") cnn.Open strCnn strSql =" SELECT * FROM songsInfo WHERE type = 'mp3' ORDER BY id DESC "Set rsFiles = Server.CreateObject (" ADODB.RecordSet " Rsfiles.cursorlocation = 3 Rsfiles.open strsql, CNN, 2, 3 'Stop execution, stop execution, output error if typeename (RSFiles) = "nothing" the response.write ("Open Recordset Error
" ) Response.end () end if%> > If r s = "URL1, URL2, URL3"; this is the File name Strurl = rsfiles.fields ("Name") ' "URL") 'This is a URL RSFILES.MOVENEXT Do While Not Rsfiles.eof Strname = Strname & "& Rosfiles.Fields (" Name ") Strurl = Strurl &" & Replace (rsfiles.fields (" URL ") RSFI Les.Movenext loop endiff 输 output response.write ("VAR URL =" & Chr (34) & Strurl & Chr (34) & "; & Vbcrlf &" Var SongName = "& Chr (34) & Strname & Chr ( 34) & ";" & VBCRLF) 'Close the data set, release resources set rsfiles = Nothing cn.close () set cnn =
Nothing%> Myflashobj.Setvariable ("VARURL", Sound [INDEXREAD]); MyFlashobj.Setvariable ("VarsongName", Songname [IIndexread]); script> The above ASP code, in fact, sfmp.php is also very simple, linking database is replaced with mysql_connect / mysql_db_query / mysql_fetch_Object The corresponding function response.write () is replaced with ECHO. Since my PHP page is not used by JavaScript and Flash interaction (but below the way I will talk about directly, I don't have this code, I am embarrassed.
ADD.ASP (PHP) program logic:
This is more simple, you need a table and an ASP (PHP) code to get it: this is an HTML form, which is included in the Add.asp (PHP) file, its action is pointing to yourself.