开发者

Play a remote audio in an HTML web page in background

开发者 https://www.devze.com 2023-02-02 07:04 出处:网络
I want to click on a button and play a sound say MP3 file. But开发者_开发技巧 the problem is that if HTML file and sound file are placed in same directory then it works but if I have to play a sound f

I want to click on a button and play a sound say MP3 file. But开发者_开发技巧 the problem is that if HTML file and sound file are placed in same directory then it works but if I have to play a sound file located with any other remote URL then it the file cannot be found.

Can anybody suggest what I should do to play a remote audio file?

I got an idea from here: http://wpaudioplayer.com/standalone

code:

  <html>  
       <head>  
           <title>Your website</title> 
           <script type="text/javascript" src="audio-player.js"></script>  
           <script type="text/javascript">  
               AudioPlayer.setup("player.swf", {width: 290});  
           </script>      
       </head>  
       <body>       
           <p id="audioplayer_1">Alternative content</p>  
           <script type="text/javascript">  
           AudioPlayer.embed("audioplayer_1", 
{soundFile: "http://www.otherwebsite.com/play.mp3"});  
           </script>     
       </body>  
   </html> 


You're sure that the paths of "player.swf", "audio-player.js" and "your.mp3" are correct? It would be better that you try to write the absolute paths of these files.

  <html>  
       <head>  
           <title>Your website</title> 
           <script type="text/javascript" src="http://www.website.com/path/audio-player.js"></script>  
           <script type="text/javascript">  
               AudioPlayer.setup("http://www.website.com/path/player.swf", {width: 290});  
           </script>      
       </head>  
       <body>       
           <p id="audioplayer_1">Alternative content</p>  
           <script type="text/javascript">  
           AudioPlayer.embed("audioplayer_1", 
{soundFile: "http://www.otherwebsite.com/play.mp3"});  
           </script>     
       </body>  
   </html>


Flash Player security sanbox can cause such problem. In this case you need to place a crossdomain.xml file (i dont remember exact content of such file) on server where mp3 file is located

0

精彩评论

暂无评论...
验证码 换一张
取 消