简体   繁体   中英

Why aren't SoundManager2 controls displayed on my page?

I have a page with the SoundManager2 control for playing back MP3 file. When I open the page, the HTML code looks like shown below and I hear the sound of the MP3 file.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Free, open song contest</title>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<section id="content">

<h2>Free, open song contest</h2>
 <div id="sm2-container">
  <!-- SM2 flash goes here -->
 </div>
<script src="/js/soundmanagerv297a-20150601/script/soundmanager2.js"></script>
<script>
soundManager.setup({
  url: '/js/soundmanagerv297a-20150601/swf/',
  onready: function() {
    var mySound = soundManager.createSound({
      url: 'http://localhost:3000/songs/Sleep%20Away.mp3'
    });
    mySound.play();
  }
});
</script>

</section>
</body>
</html>

That's what it looks like:

屏幕截图1

Why aren't the controls (play, pause etc.) displayed? How do I need to change my code in order for them to be visible?

I don't see any "wrong URL" problems in the dev console:

开发控制台

Neither do I see any errors in the JS console:

JS控制台

Update 1 (20.02.2016 07:55 MSK): I adapted the file so that now I can start the playback of a particular song. Here's what the page looks like now:

播放器

However, there is an error: When I press the "Play" button second time, the playback is not paused (as I expect). I don't see any obvious errors in the console.

Soundmanager2 does not have a ui - its just an api for playing sound. The UI you see at their site is a completely different library called Bar UI. You have to copy the html and other relevant code from the demo. Coincidentally I figured this out a couple of days ago and wrote up something about it: how to use Bar UI

[edit]updating per the posts below[/edit]

Bar UI bootstraps itself so there is nothing that you need to do as long as you have the proper Bar UI HTML in your page. Also, the playlist is present in the Bar UI HTML via a series of list items. Bar UI therefore requires no "initing" per se, if the HTML is there and the playlist is filled out it just works. There is a Bar UI API that gives you access to songs and playlists that you can see if you log a Bar UI instance to the console. But again, as long as you have a) all the needed scripts/css in the page and b) all the necessary html already in the page, then everything will "just work" when the page reloads.

You need to have these things in your page:

  • SoundManager2's js
  • Bar UI CSS
  • Bar UI js
  • Bar UI HTML

Bar UI does not have a downloadable package, you have to view the demo page 's source to get all the needed assets.

Note that the Bar UI CSS uses svg for its UI so you have to look at the Bar UI CSS to figure out what and where to put those files on your own server. Of course, you can edit the CSS to fit where you prefer to place the svg files.

As an alternative to Bar UI, you may also want to check out pushtape-player.js which may be easier to theme. It uses minimal CSS + Fontawesome icons, allowing you to render the UI in many different ways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM