I. Upload and play audio files
Find a third-party control named aspnetpager on the Internet and reference the aspnetpager. dll file to the bin of the project. It can be called directly on the webpage. Reference namespace using telerik. webcontrols;
> Upload
CopyCode The Code is as follows: protected void button#click (Object sender, eventargs E)
{
Foreach (uploadedfile file in raduploadcontext. Current. uploadedfiles)
{
If (file. filename! = NULL & file. filename! = "")
{
String strtime = memberid. tostring () + "-" + datetime. now. year. tostring () + datetime. now. month. tostring () + datetime. now. day. tostring () + datetime. now. hour. tostring () + datetime. now. minute. tostring () + datetime. now. millisecond. tostring ();
String namefile = file. filename; // get the original file name
String namelast = namefile. substring (namefile. lastindexof ("."); // get the file extension name, lastindexof ()-return the location of characters in parentheses
String filepath = system. appdomain. currentdomain. basedirectory + @ "SaveFilePath/mbmusic/"; // File Upload path
System. Io. fileinfo Fi = new system. Io. fileinfo (file. filename );
If (Fi. extension. tolower () = ". MP3 "| fi. extension. tolower () = ". WMA "| fi. extension. tolower () = ". RM "| fi. extension. tolower () = ". wav ")
{
String name = strtime + namelast; // name of the last saved file
Music = "http://www.cnblogs.com/SaveFilePath/MBmusic/" + name;
Filesizes = int. parse (file. contentlength. tostring ());
String Path = filepath + name;
If (file. exists (PATH) = false)
{
File. saveas (filepath + name );
Mf. mf_path = mV;
// MF. mf_path = mV;
}
Else if (file. exists (PATH) = true)
{
Name = strtime + "(" + tt + ")" + namelast;
File. saveas (filepath + name );
Music = "http://www.cnblogs.com/SaveFilePath/MBmusic/" + name;
Mf. mf_path = mV;
// MF. mf_path = mV;
}
If (remainbytesize> = filesizes)
{
Try
{
// Insert data into the database
If (addnum> 0 & udpsize> 0)
{
// Response. Write ("<SCRIPT> alert ('upload successful !! ') </SCRIPT> ");
// BIND ();
}
Else
{
Response. Write ("<SCRIPT> alert ('upload failed !! ') </SCRIPT> ");
Return;
}
Num ++;
}
Catch {}
}
Else
{
Response. Write ("<SCRIPT> alert ('space is insufficient. Please apply for space !! ') </SCRIPT> ");
Return;
}
}
Else
{
Response. Write ("<SCRIPT> alert ('upload file format error! The file format is MP3, WMA, WAV. rm! ') </SCRIPT> ");
Return;
}
}
Else
{
Response. Write ("<SCRIPT> alert ('select the uploaded file') </SCRIPT> ");
Return;
}
}
}
> Playback
1. Add the literal1 control on the playback page.
2. Add and call the audio player code in the background of the page.Copy code The Code is as follows: public static string getflashtext (string URL)
{
String STR = @ "<Object ID = 'mediaplayer' classid = 'clsid: 6bf52a52-394a-11d3-b153-00c04f79faa6 'height = '62 'width = '2016'>
<Param name = 'rate' value = '1'/>
<Param name = 'balance 'value = '0'/>
<Param name = 'currentposition' value = '0'/>
<Param name = 'defaultframe 'value = ''/>
<Param name = 'playcount' value = '1'/>
<Param name = 'autostart' value = '-1'/>
<Param name = 'currentmarker' value = '0'/>
<Param name = 'invokeurls' value = '-1'/>
<Param name = 'baseurl' value = ''/>
<Param name = 'Volume 'value = '2'/>
<Param name = 'mute' value = '0'/>
<Param name = 'uimode' value = 'full'/>
<Param name = 'stretchtofit 'value = '0'/>
<Param name = 'windowlessvideo' value = '0'/>
<Param name = 'enabled' value = '-1'/>
<Param name = 'enablescontextmenu 'value = '0'/>
<Param name = 'fullscreen' value = '0'/>
<Param name = 'samples' value = ''/>
<Param name = 'sample' value = ''/>
<Param name = 'samifilename' value = ''/>
<Param name = 'captioningid' value = ''/>
<Param name = 'enableerrordialogs 'value = '0'/>
<Param name = '_ CX' value = '000000'/>
<Param name = '_ Cy' value = '000000'/>
<Param name = 'url' value = '"+ URL +"'/> </Object> ";
Return STR;
}
3. Call the getflashtext () method
copy Code the code is as follows: public void bindmusic ()
{< br> If (mfid! = 0)
{< br> dataset DST = mf. Search (mfid);
If (DST! = NULL & DST. tables [0]. rows. count> 0)
{< br> string url = DST. tables [0]. rows [0] ["mf_path"]. tostring ();
string [] STRs = URL. split (New char [] {'/'});
string mvname = STRs [STRs. length-1];
string url1 = "SaveFilePath/mbmv/" + mvname;
literal1.text = getflashtext (URL ); // call literal1 to play audio.
label1.text = DST. tables [0]. rows [0] ["mf_filename"]. tostring ();
// txt_filename.text = DST. tables [0]. rows [0] ["mf_filename"]. tostring ();
// txt_introduction.text = DST. tables [0]. rows [0] ["mf_introduction"]. tostring ();
}< BR >}