Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to hide the playback file address of MediaPlayer control in ASP

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to hide the MediaPlayer control playback file address in ASP, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

When playing a video, you can see the address of the video file by directly viewing the source file of the page. The MediaPlayer control player will add the following initialization statement to the page:

MediaPlayer control initialization can be viewed to the source file address

Sys.Application.add_init (function () {$create (Sys.UI.Silverlight.MediaPlayer, {"autoPlay": true, "mediaSource": "http://211.142.31.235/Nas1/VOD/CP0001/490Kbps/D/DI/DIA/DiaoZhongYuan1/DiaoZhongYuan1.wmv","scaleMode":2,"source":"UserControl/playerTheme/player.xaml","volume":1}, null, null, $get (" myUserMediaPlayer_player_parent "));})

The solution is to first establish a string encryption and decryption service.

Encryption and decryption tool class

A pair of strings to carry out, Encryption and decryption tool class 3 / 4 public class DESEncryptor5 {6 static public method # region static public method 7 / * * / 8 / A pair of strings are encrypted 9 / 10 / source string 11 / encrypted string 12 public static string ExecEncrypt (string strSource) 13 {14 DESEncryptor desEncryptor = new DESEncryptor () 15 desEncryptor.InputString = strSource; 16 desEncryptor.DesEncrypt (); 17 return desEncryptor.OutString 18} 19 / * * / 20 / / A pair of encrypted strings is decrypted 21 / / 22 / / the encrypted string 23 / restored string 24 public static string ExecDeEncrypt (string strSource) 25 {26 DESEncryptor desEncryptor = new DESEncryptor (); 27 desEncryptor.InputString = strSource 28 desEncryptor.DesDecrypt (); 29 return desEncryptor.OutString; 30} 31 # endregion3233 Private member # region Private member 34 / * * / 35 / input string 36 / 37 private string inputString=null 38 / * * / 39 / output string 40 / / 41 private string outString=null; 42 / * * / 43 / input file path 44 / 45 private string inputFilePath=null 46 / * * / 47 / output file path 48 / / 49 private string outFilePath=null; 50 / * / 51 / encryption key 52 / 53 private string encryptKey= "fanmenglife" 54 / * / 55 / decryption key 56 / 57 private string decryptKey = "fanmenglife"; 58 / * / 59 / prompt 60 / 61 private string noteMessage=null 62 # endregion 6364 Public attribute # region Public attribute 65 / * * / 66 / input string 67 / 68 public string InputString 69 {70 get {return inputString;} 71 set {inputString=value } 72} 73 / * * / 74 / / output string 75 / 76 public string OutString 77 {78 get {return outString;} 79 set {outString=value } 80} 81 / * * / 82 / / enter the file path 83 / 84 public string InputFilePath 85 {86 get {return inputFilePath;} 87 set {inputFilePath=value } 88} 89 / * * / 90 / / output file path 91 / 92 public string OutFilePath 93 {94 get {return outFilePath;} 95 set {outFilePath=value } 96} 97 / * * / 98 / encryption key 99 / / 100 public string EncryptKey 101 {102 get {return encryptKey;} 103 set {encryptKey=value The decryption key public string DecryptKey 109 {110 get {return decryptKey;} 111 set {decryptKey=value Error message 115 / 116 public string NoteMessage 117 {118 get {return noteMessage;} 119 set {noteMessage=value 122121 # endregion 122123 constructor # region constructor 126126127public DESEncryptor () 128129129130 / / TODO: add constructor logic here 133.133 # endregion 134135 DES encrypted string # region DES encrypted string 136Note: the key must be 8 digits 139 / 140public void DesEncrypt () 141 {142Crypt [] byKey=null 144byte [] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; 144try 145 {146byKey = System.Text.Encoding.UTF8.GetBytes (this.encryptKey.Substring (0prime8)); 147DESCryptoServiceProvider des = new DESCryptoServiceProvider (); 148byte [] inputByteArray = Encoding.UTF8.GetBytes (this.inputString); 149MemoryStream ms = new MemoryStream () 150 CryptoStream cs = new CryptoStream (ms, des.CreateEncryptor (byKey, IV), CryptoStreamMode.Write); 151cs.Write (inputByteArray, 0, inputByteArray.Length); 152cs.FlushFinalBlock (); 153this.outString=Convert.ToBase64String (ms.ToArray ()); 155155catch (System.Exception error) 156 {157this.noteMessage=error.Message 159159160 # endregion 161162 DES decryption string # region DES decryption string 16616 / / 166decryption string 165166public void DesDecrypt () 167 {168byte [] byKey = null; 169byte [] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF} 170byte [] inputByteArray = new Byte [this.inputString.Length]; 171173byKey = System.Text.Encoding.UTF8.GetBytes (decryptKey.Substring (0mem8)); 174DESCryptoServiceProvider des = new DESCryptoServiceProvider (); 175inputByteArray = Convert.FromBase64String (this.inputString); 176MemoryStream ms = new MemoryStream () CryptoStream cs = new CryptoStream (ms, des.CreateDecryptor (byKey, IV), CryptoStreamMode.Write); 178cs.Write (inputByteArray, 0, inputByteArray.Length); 179cs.FlushFinalBlock (); 180System.Text.Encoding encoding = new System.Text.UTF8Encoding (); 181this.outString=encoding.GetString (ms.ToArray ()) 188183catch (System.Exception error) 188185this.noteMessage=error.Message; 188188188 # endregion 189}

Encrypt and decrypt WebService, and call the encryption and decryption methods in the tool:

1 WebService To allow this WebService to be called from script / 2 / / Summary description for Service13 / / 4 [WebService (Namespace = "System.ComponentModel.ToolboxItem [WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)] 6 [System.ComponentModel.ToolboxItem (false)] 7 / / To allow this WebService to be called from script, using ASP.NET AJAX, uncomment the following line. 8 / / [System.Web.Script.Services.ScriptService] 9 public class Service1: System.Web.Services.WebService10 {11 / * * / 12 / encryption 13 / 14 / / address 15 / 16 [WebMethod] 17 public string Encrypt (string url) 18 {19 return DESEncryptor.ExecEncrypt (url) 20} 2122 / * / 23 / / decryption 24 / 25 / / address 26 / 27 [WebMethod] 28 public string DeEncrypt (string url) 29 {30 return DESEncryptor.ExecDeEncrypt (url); 31} 32}

When the MediaPlayer control playback page is loaded, first call the encryption method in WebService to encrypt the playback address, and then register the JavaScript script to call the video file playback method:

Playback page loading

Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {/ / encrypt the playback URL string encryptUrl = local.Encrypt (playUrl) / / register the script and call the javascript playback method Page.ClientScript.RegisterStartupScript (this.GetType (), "", "setTimeout (\" onPlay ('"+ encryptUrl +")\ ", 1000)", true);}}

JavaScript calls WebService through WebService.htc provided by Microsoft. To use WebService.htc in ASP.NET, you need to add the following code to the HTML code:

Note: the div must be outside the forms

Javascript Code:

1 function getUrl (str) {2 / / * parameters are the url of webservice, followed by the name 3 serviceDiv.useService ("http://localhost:88/Service1.asmx?WSDL"," news "); 4 / / set a callback function, which is called back when service returns the result * the parameter is the name of the callback function, followed by the parameter 5 intCallID = serviceDiv.news.callService (url_result, "DeEncrypt", str) of webservice; / / there are two arguments. 6} 7 8 function url_result (result) / / callback function 9 {10 var media_player = $find ('myUserMediaPlayer_player'); 11 media_player.set_mediaSource (result.value); 12 media_player.set_autoPlay (true) 13} 14 15 function onPlay (str) {16 getUrl (str); 17}

There are a few points to make:

1. Why the script registered in the Page_Load event does not directly call the playback method in Javascript, because the WebService.htc will not be initialized until the page is fully loaded, so I use the setTimeout method to delay calling the playback method for a period of time.

two。 Remember to judge whether the returned result is successful or not when using the WebService callback function.

With the above method, the playback file address cannot be found when viewing the source file on the page, and the MediaPlayer initialization statement is updated as follows:

MediaPlayer control initialization after change

Sys.Application.add_init (function () {$create (Sys.UI.Silverlight.MediaPlayer, {"autoPlay": true, "scaleMode": 1, "source": ".. / UserControl/playerTheme/VIPPlayer.xaml", "volume": 1}, null, null, $get ("ump_player_parent"));}) Thank you for reading this article carefully. I hope the article "how to hide the playback file address of MediaPlayer controls in ASP" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report