{"id":6675,"date":"2011-03-17T03:21:54","date_gmt":"2011-03-17T07:21:54","guid":{"rendered":"http:\/\/info.template-help.com\/?p=6675"},"modified":"2015-09-11T05:17:10","modified_gmt":"2015-09-11T09:17:10","slug":"jquery-jplayer","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/jquery-jplayer.html","title":{"rendered":"jQuery &#8220;jPlayer&#8221;"},"content":{"rendered":"Jplayer is a flexible and functional solution to play and control media files in your webpage. It supports HTML5 and outputs flash for browsers that yet do not support HTML 5. Among other advantages is the ability to customize its appearance using HTML and CSS.  For more details visit the official website http:\/\/www.jplayer.org\r\n\r\n<h3>JavaScript<\/h3>\r\nWe should include jQuery framework and jplayer.min.js by pointing src attribute in the script tag to those .js files.\r\n\r\n<pre class=\"brush:js\">\r\n&lt;script type=\"text\/javascript\" src=\"js\/jquery-1.4.2.min.js\" >&lt;\/script>\r\n&lt;script type=\"text\/javascript\" src=\"js\/jplayer.min.js\">&lt;\/script>\r\n<\/pre>\r\n\r\nInitialization script we place in the <head> section. Define the list of songs in the array myPlayList (line 4-6) Notice, that that you should specify two audio files: mp3 and ogg. You can use any sound conversion tool for that (e.g. http:\/\/media.io)\r\n\r\n<pre class=\"brush:js\">\r\n$(document).ready(function(){\r\n    var playItem = 0;\r\n    var myPlayList = [\r\n        {name:\"Black Plant\",mp3:\"audio\/black_plant.mp3\",ogg:\"audio\/black_plant.ogg\"},\r\n        {name:\"Hidden\",mp3:\"audio\/hidden.mp3\",ogg:\"audio\/hidden.ogg\"},\r\n        {name:\"The Separation\",mp3:\"audio\/separation.mp3\",ogg:\"audio\/separation.ogg\"}\r\n    ];\r\n\r\n    \/\/ Local copy of jQuery selectors, for performance.\r\n    var jpPlayTime = $(\"#jplayer_play_time\");\r\n    var jpTotalTime = $(\"#jplayer_total_time\");\r\n\r\n    $(\"#jquery_jplayer\").jPlayer({\r\n        ready: function() {\r\n            displayPlayList();\r\n            playListInit(true); \/\/ Parameter is a boolean for autoplay.\r\n        },\r\n        oggSupport: true\r\n    })\r\n    .jPlayer(\"onProgressChange\", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {\r\n        jpPlayTime.text($.jPlayer.convertTime(playedTime));\r\n        jpTotalTime.text($.jPlayer.convertTime(totalTime));\r\n    })\r\n    .jPlayer(\"onSoundComplete\", function() {\r\n        playListNext();\r\n    });\r\n\r\n    $(\"#jplayer_previous\").click( function() {\r\n        playListPrev();\r\n        $(this).blur();\r\n        return false;\r\n    });\r\n\r\n    $(\"#jplayer_next\").click( function() {\r\n        playListNext();\r\n        $(this).blur();\r\n        return false;\r\n    });\r\n\r\n    function displayPlayList() {\r\n        $(\"#jplayer_playlist ul\").empty();\r\n        for (i=0; i < myPlayList.length; i++) {\r\n            var listItem = (i == myPlayList.length-1) ? \"<li class='jplayer_playlist_item_last'>\" : \"<li>\";\r\n            listItem += \"<a href='#' id='jplayer_playlist_item_\"+i+\"' tabindex='1'>\"+ myPlayList[i].name +\"<\/a><\/li>\";\r\n            $(\"#jplayer_playlist ul\").append(listItem);\r\n            $(\"#jplayer_playlist_item_\"+i).data( \"index\", i ).click( function() {\r\n                var index = $(this).data(\"index\");\r\n                if (playItem != index) {\r\n                    playListChange( index );\r\n                } else {\r\n                    $(\"#jquery_jplayer\").jPlayer(\"play\");\r\n                }\r\n                $(this).blur();\r\n                return false;\r\n            });\r\n        }\r\n    }\r\n\r\n    function playListInit(autoplay) {\r\n        if(autoplay) {\r\n            playListChange( playItem );\r\n        } else {\r\n            playListConfig( playItem );\r\n        }\r\n    }\r\n\r\n    function playListConfig( index ) {\r\n        $(\"#jplayer_playlist_item_\"+playItem).removeClass(\"jplayer_playlist_current\").parent().removeClass(\"jplayer_playlist_current\");\r\n        $(\"#jplayer_playlist_item_\"+index).addClass(\"jplayer_playlist_current\").parent().addClass(\"jplayer_playlist_current\");\r\n        playItem = index;\r\n        $(\"#jquery_jplayer\").jPlayer(\"setFile\", myPlayList[playItem].mp3, myPlayList[playItem].ogg);\r\n    }\r\n\r\n    function playListChange( index ) {\r\n        playListConfig( index );\r\n        $(\"#jquery_jplayer\").jPlayer(\"play\");\r\n    }\r\n\r\n    function playListNext() {\r\n        var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;\r\n        playListChange( index );\r\n    }\r\n\r\n    function playListPrev() {\r\n        var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;\r\n        playListChange( index );\r\n    }\r\n\r\n});\r\n<\/pre>\r\n\r\n<h3>HTML<\/h3>\r\nBelow you can see general HTML script representation:\r\n\r\n<pre class=\"brush:html\">\r\n<div id=\"jquery_jplayer\"><\/div>\r\n<div class=\"jp-single-player\">\r\n  <div class=\"jp-interface\">\r\n    <ul class=\"jp-controls\">\r\n      <li><a href=\"#\" id=\"jplayer_play\" class=\"jp-play\" tabindex=\"1\">play<\/a><\/li>\r\n      <li><a href=\"#\" id=\"jplayer_pause\" class=\"jp-pause\" tabindex=\"1\">pause<\/a><\/li>\r\n      <li><a href=\"#\" id=\"jplayer_stop\" class=\"jp-stop\" tabindex=\"1\">stop<\/a><\/li>\r\n      <li><a href=\"#\" id=\"jplayer_volume_min\" class=\"jp-volume-min\" tabindex=\"1\">min volume<\/a><\/li>\r\n      <li><a href=\"#\" id=\"jplayer_volume_max\" class=\"jp-volume-max\" tabindex=\"1\">max volume<\/a><\/li>\r\n    <\/ul>\r\n    <div class=\"jp-progress\">\r\n      <div id=\"jplayer_load_bar\" class=\"jp-load-bar\">\r\n        <div id=\"jplayer_play_bar\" class=\"jp-play-bar\"><\/div>\r\n      <\/div>\r\n    <\/div>\r\n    <div id=\"jplayer_volume_bar\" class=\"jp-volume-bar\">\r\n      <div id=\"jplayer_volume_bar_value\" class=\"jp-volume-bar-value\"><\/div>\r\n    <\/div>\r\n    <div id=\"jplayer_play_time\" class=\"jp-play-time\"><\/div>\r\n    <div id=\"jplayer_total_time\" class=\"jp-total-time\"><\/div>\r\n  <\/div>\r\n  <div id=\"jplayer_playlist\" class=\"jp-playlist\">\r\n    <ul>\r\n      <li>Bubble<\/li>\r\n    <\/ul>\r\n  <\/div>\r\n<\/div>\r\n<\/pre>\r\n\r\n<h3>CSS<\/h3>\r\nInclude the default theme for the player by connecting the .css file in the <head> section of the .html file\r\n\r\n<pre class=\"brush:html\">\r\n&tl;link href=\"path\/to\/file\/jplayer.blue.monday.css\" rel=\"stylesheet\" type=\"text\/css\" \/>\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>Jplayer is a flexible and functional solution to play and control media files in your webpage. It supports HTML5 and outputs flash for browsers that yet do not support HTML 5. Among other advantages is the ability to customize its appearance using HTML and CSS. For more details visit the official website http:\/\/www.jplayer.org JavaScript We [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[264,270],"tags":[813,820],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/6675"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=6675"}],"version-history":[{"count":0,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/6675\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=6675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=6675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=6675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}