Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:19+00:00 2026-06-16T00:14:19+00:00

My JavaScript framework: jQuery 1.8.3 Using mediaelement.js and playlist to play audio (from this

  • 0

My JavaScript framework: jQuery 1.8.3

Using mediaelement.js and playlist to play audio (from this thread)
mediaelement.js and custom playlist

I’ve been trying to figure out how to change the script (at bottom) to use this kind of list:

 <ul class="mejs-list">
     <li class="current"><a href="/media/file-1.mp3">Nice Name for file1</a> 
       other random text or html/img, file description etc </li>
    <li><a href="/media/file-2.mp3">Nice Name for file2</a>other text or html/img</li>
    <li><a href="/media/file-3.mp3">Nice Name for file3</a>other text or html/img</li>
</ul>

instead of this one

<ul class="mejs-list">
  <li>/media/file-1.mp3</li>
  <li class="current">/media/file-2.mp3</li>
  <li>/media/file-3.mp3</li>
</ul>

This script turns this list into a playlist, and works very well, but creates links displaying full path, I prefer to grab the src from the link instead of just the text inside the li, so I can use better names.

<script>
$(function(){
    $('audio').mediaelementplayer({
        success: function (mediaElement, domObject) {
            mediaElement.addEventListener('ended', function (e) {
                mejsPlayNext(e.target);
            }, false);
        },
        keyActions: []
    });

    $('.mejs-list li').click(function() {
        $(this).addClass('current').siblings().removeClass('current');
        var audio_src = $(this).text();
        $('audio#mejs:first').each(function(){
            this.player.pause();
            this.player.setSrc(audio_src);
            this.player.play();
        });
    });

});

function mejsPlayNext(currentPlayer) {
    if ($('.mejs-list li.current').length > 0){ // get the .current song
        var current_item = $('.mejs-list li.current:first'); // :first is added if we have few .current classes
        var audio_src = $(current_item).next().text();
        $(current_item).next().addClass('current').siblings().removeClass('current');
        console.log('if '+audio_src);
    }else{ // if there is no .current class
        var current_item = $('.mejs-list li:first'); // get :first if we don't have .current class
        var audio_src = $(current_item).next().text();
        $(current_item).next().addClass('current').siblings().removeClass('current');
        console.log('elseif '+audio_src);
    }

    if( $(current_item).is(':last-child') ) { // if it is last - stop playing
        $(current_item).removeClass('current');
    }else{
        currentPlayer.setSrc(audio_src);
        currentPlayer.play();
    }
}
</script>

If there’s a better way to do it using jQuery and mediaelement.js I’m open to suggestions.

p.s.
Would also be a plus if I could have previous and next track links, but it’s not required.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:14:19+00:00Added an answer on June 16, 2026 at 12:14 am

    Figured it out and posting answer for everyone’s benefit.

    HTML

    <audio id="mejs" src="track1.mp3" type="audio/mp3" controls></audio>
    <ul class="mejs-list">
      <li id="track1.mp3">Track1</li>
      <li id="track2.mp3">Track2</li>
      <li id="track3.mp3">Track3</li>
    </ul>
    

    javascript

        <script>
            $(function(){
                $('audio').mediaelementplayer({
                    success: function (mediaElement, domObject) {
                        mediaElement.addEventListener('ended', function (e) {
                            mejsPlayNext(e.target);
                        }, false);
                    },
                    keyActions: []
                });
    
                $('.mejs-list li').click(function() {
                    $(this).addClass('current').siblings().removeClass('current');
                    var audio_src = this.id;
                    $('audio#mejs:first').each(function(){
                        this.player.pause();
                        this.player.setSrc(audio_src);
                        this.player.play();
                    });
                });
    
            });
    
            function mejsPlayNext(currentPlayer) {
                if ($('.mejs-list li.current').length > 0){ // get the .current song
                    var current_item = $('.mejs-list li.current:first'); // :first is added if we have few .current classes
                    var audio_src = $(current_item).next().text();
                    $(current_item).next().addClass('current').siblings().removeClass('current');
                    console.log('if '+audio_src);
                }else{ // if there is no .current class
                    var current_item = $('.mejs-list li:first'); // get :first if we don't have .current class
                    var audio_src = $(current_item).next().text();
                    $(current_item).next().addClass('current').siblings().removeClass('current');
                    console.log('elseif '+audio_src);
                }
    
                if( $(current_item).is(':last-child') ) { // if it is last - stop playing
                    $(current_item).removeClass('current');
                }else{
                    currentPlayer.setSrc(audio_src.match('http.*\.mp3'));
                    currentPlayer.play();
                }
            }
            </script>
    

    NOTE: this dose not validate HTML standerds(WC3), but it dose work, Tested
    Chrome, Safari, Firefox on mac, latest versions
    Still looking for HTML compliant version to validate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load an image asynchronously using jquery javascript framework. The loaded image
My latest project is using a javascript framework (jQuery), along with some plugins (validation,
Using only JavaScript and framework like dojo/jQuery... Is there a way to find the
I am trying to write my own Javascript Framework something like jQuery. I use
I'm new to both Javascript and the framework jQuery. Basically I'm trying to say
Without using a JavaScript framework like jQTouch and jQuery Mobile, is there a way
I have been building a dynamic form in my Zend Framework application using Jquery
I'm looking to find a galleria replacement, hopefully using jQuery but other javascript frameworks
I was under the impression that jQuery is JavaScript Framework, but when am searching
wondering if some of you know what javascript framework facebook is using ? Thanks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.