mp3 player in HTML website [closed]

2019-03-16 19:21发布

问题:

I want insert a simple mp3 player into my website. The Mp3 player must have just 2 buttons (play and pause).

I found this: http://www.schillmania.com/projects/soundmanager2/ and it seems nice but I could not make it have those two buttons. Can anyone help me find a way to insert an mp3 player in this way?

回答1:

I was doing a research about the subject few months ago for play sound in a game, and SoundManager is the easier way to play audio using JavaScript.

First way:

If you go to the documentation, you will see that SoundManager intercepts clicks to MP3 links and plays them inline. The script assigns additional CSS classes to the links to indicate their state (playing/paused, etc.)

<a href="/mp3/foo.mp3" title="Play sound" class="sm2_button">Play Link</a>

Check demo and more info

Second way

If you want to use personalized buttons instead of links, or images, or any other html element, you can use the onClick event to play/pause sound, for example:

Loading the sound:

<script>
soundManager.onready(function() {
   soundManager.createSound({id:'mySound1',url:'/audio/foo.mp3'});
"
});
</script>

The buttons:

<button id="play" onclick="soundManager.play('mySound1');return false">Play Button</button>
<button id="pause" onclick="soundManager.pause('mySound1');return false">Pause Button</button>

You can found more info on the API



回答2:

In general, to play the audio file there are two main ways which are to use a premade flash object (or make it your self if you have actionscript skills) or use the HTML5 audio tag and javascript controls. If you are looking for a flash player try activeden which has 1000s of small players for sale and hopefully something can meet your needs. Here is how you can insert a flash object into you page.