1

I'm implementing an sticky audio player on a website and it's working fine. However, I'd like to create a play button, OnClick maybe, in HTML that would give a play in the player when the user clicked on it. I tried several codes and none worked.

The last one was this and it did not work either.

<button type="button" onclick="$(this).myPlayer();">Play</button>

In addition to the Javascripts and external CSS, which are before HEAD, the script that runs the player on the page (inline) is this.

<script>
    jQuery(function($) {
        $('body').myPlayer({
            firstPlaying: 0,
            autoplay: false,
            shuffle: false,
            //veryThin: true,
            slideAlbumsName: true,
            nowplaying2title: true,
            roundedCorners: true,
            //accentColor:"#cc181e",    //008DDE            
            pluginPath: "player/",
            playlist: [ 
                {mp3:"player/music/mymusic.mp3", title:"My Song", artist:"Mine", album:"Single", cover:"player/music/cover.png"}
            ]
        });

    });
</script>

From what I was researching, many articles mention using the HTML5 tag "data- *" inside the button code. However, I could not use it correctly.

If anyone can help me, I appreciate it.

4
  • Do you know the name of the audio player plugin? Commented Dec 5, 2016 at 15:35
  • zer00ne, it's just Sticky Audio Player. Commented Dec 5, 2016 at 15:54
  • I did a quick search and there's quite a few of them out there. This plugin should have an API to which you can use the player's public methods. You'll need to know exactly which player you have so you can operate it correctly. Commented Dec 5, 2016 at 16:33
  • Yep, zer00ne. I did that and got it after a few hours! Thank you. Commented Dec 7, 2016 at 16:57

1 Answer 1

1

I may not have understood your problem correctly, but here is a snippet you can try to get this working:

<button type="button" id="play-music">Play</button>

In your script, you can write something like this:

<script>
  $(document).ready(function() {
    $("#play-music").click(function() {
      $('body').myPlayer({ ... }); // Your code here
    });
  });
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank, 31piy. Your code worked, but the mp3 file didn't play. I'd like that when I click the button, the player will already open playing the song. Anyway, thank you. That was the only tip that came closest to what I want!
@matheojean well that completely depends on the working of the player you are using. Please upvote and accept my answer if it helped you.
31piy, i got it from another way. But your tip was important for me. Anyway, thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.