A Pen by Sean Kumar on CodePen.
Created
April 5, 2020 02:40
-
-
Save pemby/49278687cdb09184d689eb5f06b56695 to your computer and use it in GitHub Desktop.
jPlayer With Playlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="sectionContainer" id="profile-music"> | |
<div class="container"> | |
<div class="sectionHeading"><h3>Media</h3></div> | |
<div class="crow"> | |
<div class="chalf"> | |
<div id="jplayer-audio" class="jp-jplayer"></div> | |
<div id="jplayer-audio-container" class="jp-audio" role="application" aria-label="media player"> | |
<div class="jp-type-playlist"> | |
<div class="jp-gui"> | |
<div class="jp-title"></div> | |
<div class="jp-volume-controls"> | |
<button class="jp-mute jp-btn" role="button" tabindex="0"><i class="fa fa-volume-mute"></i></button> | |
<button class="jp-volume-max" role="button" tabindex="0">max volume</button> | |
<div class="jp-volume-bar"> | |
<div class="jp-volume-bar-value"></div> | |
</div> | |
</div> | |
<div class="jp-toggles"> | |
<button class="jp-repeat jp-btn" role="button" tabindex="0"><i class="fa fa-repeat"></i></button> | |
<button class="jp-shuffle jp-btn" role="button" tabindex="0"><i class="fa fa-random"></i></button> | |
</div> | |
<div class="jp-controls-holder"> | |
<div class="jp-controls"> | |
<button class="jp-previous jp-btn" role="button" tabindex="0"><i class="fa fa-backward"></i></button> | |
<button class="jp-play jp-btn" role="button" tabindex="0"><i class="fa fa-play"></i></button> | |
<button class="jp-stop jp-btn" role="button" tabindex="0"><i class="fa fa-stop"></i></button> | |
<button class="jp-next jp-btn" role="button" tabindex="0"><i class="fa fa-forward"></i></button> | |
</div> | |
<div class="jp-progress"> | |
<div class="jp-seek-bar"> | |
<div class="jp-play-bar"></div> | |
</div> | |
</div> | |
<div class="jp-times"> | |
<div class="jp-current-time" role="timer" aria-label="time"> </div> | |
<div class="jp-duration" role="timer" aria-label="duration"> </div> | |
</div> | |
</div> | |
</div> | |
<div class="jp-playlist"> | |
<ul> | |
<li> </li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="chalf"> | |
<div id="jp_video_container" class="jp-video jp-video-270p" role="application" aria-label="media player"> | |
<div class="jp-type-playlist"> | |
<div id="jp_video" class="jp-jplayer"></div> | |
<div class="jp-gui"> | |
<div class="jp-video-play"> | |
<button class="jp-video-play-icon" role="button" tabindex="0" style="display: none;"><i class="fa fa-play-circle-o" aria-hidden="true"></i></button> | |
</div> | |
<div class="jp-interface"> | |
<div class="jp-progress"> | |
<div class="jp-seek-bar"> | |
<div class="jp-play-bar"></div> | |
</div> | |
</div> | |
<div class="jp-current-time" role="timer" aria-label="time"> </div> | |
<div class="jp-duration" role="timer" aria-label="duration"> </div> | |
<div class="jp-controls-holder"> | |
<div class="jp-controls"> | |
<button class="jp-previous" role="button" tabindex="0"><i class="fa fa-backward" aria-hidden="true"></i></button> | |
<button class="jp-play" role="button" tabindex="0"><i class="fa fa-play" aria-hidden="true"></i></button> | |
<button class="jp-next" role="button" tabindex="0"><i class="fa fa-forward" aria-hidden="true"></i></button> | |
<button class="jp-stop" role="button" tabindex="0"><i class="fa fa-stop" aria-hidden="true"></i></button> | |
</div> | |
<div class="jp-volume-controls"> | |
<button class="jp-mute" role="button" tabindex="0"><i class="fa fa-volume-off" aria-hidden="true"></i></button> | |
<button class="jp-volume-max" role="button" tabindex="0"><i class="fa fa-volume-up" aria-hidden="true"></i></button> | |
<div class="jp-volume-bar"> | |
<div class="jp-volume-bar-value"></div> | |
</div> | |
</div> | |
<div class="jp-toggles"> | |
<button class="jp-repeat" role="button" tabindex="0"><i class="fa fa-repeat" aria-hidden="true"></i></button> | |
<button class="jp-shuffle" role="button" tabindex="0"><i class="fa fa-random" aria-hidden="true"></i></button> | |
<button class="jp-full-screen" role="button" tabindex="0"><i class="fa fa-arrows-alt" aria-hidden="true"></i></button> | |
</div> | |
</div> | |
<div class="jp-details"> | |
<div class="jp-title" aria-label="title"> </div> | |
</div> | |
</div> | |
</div> | |
<div class="jp-playlist"> | |
<ul> | |
<!-- The method Playlist.displayPlaylist() uses this unordered list --> | |
<li> </li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
/* Load jPlayer */ | |
new jPlayerPlaylist({ | |
jPlayer: "#jp_video", | |
cssSelectorAncestor: "#jp_video_container" | |
}, [ | |
{ | |
type: "youtube", | |
title: "Jai Wolf - Indian Summer (Official Music Video)", | |
m4v:"https://www.youtube.com/watch?v=qbGZDEFHBmc", | |
},{ | |
type: "youtube", | |
title: "Boom Shankar", | |
m4v:"https://www.youtube.com/watch?v=NqkkTaGvwNQ", | |
} | |
], { | |
playlistOptions: { | |
autoPlay: false | |
}, | |
supplied: "m4v", | |
smoothPlayBar: true, | |
keyEnabled: false, | |
autoBlur: false, | |
}); | |
/* Youtube Integration Setup */ | |
var setupYoutube = function(whereDivTo, width, height) { | |
$("<div>").attr("id", "ytplayer").appendTo(whereDivTo); | |
onYouTubeIframeAPIReady = function() { | |
youtubeApi = new YT.Player("ytplayer", { | |
width: width, | |
height: height, | |
videoId: "cfLob5IYMp8", | |
playerVars: { | |
"autoplay": 1, | |
"color": "white", | |
"modestbranding": 1, | |
"rel": 0, | |
"showinfo": 0, | |
"theme": "light" | |
}, events: { | |
"onReady": function() { | |
$(document).trigger("ready.Youtube"); | |
}, | |
"onStateChange": "youtubeStateChange" | |
} | |
}); | |
} | |
$.getScript("//www.youtube.com/player_api"); | |
}, | |
loadYoutubeListeners = function(player, jplayer, id) { | |
var container = $(player.options.cssSelector.gui, player.options.cssSelectorAncestor); | |
youtubeStateChange = function(ytEvent) { | |
switch(ytEvent.data) { | |
case -1: | |
$(ytEvent.target.getIframe()).show(); | |
$(jplayer).find('video').hide(); | |
container.css({ 'opacity' : 0, 'z-index': -1, 'position' : 'relative' }); | |
container.find('.jp-interface').slideUp("slow"); | |
break; | |
case YT.PlayerState.ENDED: | |
$(jplayer).trigger($.jPlayer.event.ended); | |
break; | |
case YT.PlayerState.CUED: | |
$(jplayer).find('video').show(); | |
$(ytEvent.target.getIframe()).hide(); | |
container.css({ 'opacity' : 1, 'z-index': 0 }); | |
container.find('.jp-interface').slideDown("slow"); | |
} | |
}; | |
youtubeApi.loadVideoById(id); | |
} | |
$(document).on($.jPlayer.event.setmedia, function(jpEvent) { | |
var player = jpEvent.jPlayer, | |
url = player.status.src; | |
if(!player.html.video.available) return; | |
if(typeof player.status.media.type === "undefined" || player.status.media.type != 'youtube') { | |
if(window['youtubeApi']) | |
if(youtubeApi.getPlayerState() != YT.PlayerState.CUED && youtubeApi.getPlayerState() != YT.PlayerState.ENDED) | |
return youtubeApi.stopVideo(); | |
return; | |
} | |
var youtubeId = url.match(/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/)[1] | |
if(window['youtubeApi']) | |
loadYoutubeListeners(player, jpEvent.target, youtubeId); | |
else { | |
setupYoutube(jpEvent.target, player.status.width, player.status.height); | |
$(document).on("ready.Youtube", function() { | |
loadYoutubeListeners(player, jpEvent.target, youtubeId); | |
}); | |
} | |
}); | |
new jPlayerPlaylist({ | |
jPlayer: "#jplayer-audio", | |
cssSelectorAncestor: "#jplayer-audio-container" | |
}, [ | |
{ | |
title: "Jai Wolf - Indian Summer", | |
mp3: "https://geo-samples.beatport.com/track/f360147d-297a-42f9-8996-d952160b3a30.LOFI.mp3", | |
}, { | |
title: 'Friends', | |
mp3: 'https://geo-samples.beatport.com/track/0fd1272a-9a9e-4640-a280-f3d147276de3.LOFI.mp3', | |
} | |
], { | |
swfPath: "src/swf/", | |
solution: "html, flash", | |
supplied: "mp3", | |
preload: "auto", | |
wmode: "window", | |
useStateClassSkin: true, | |
autoBlur: false, | |
smoothPlayBar: true, | |
keyEnabled: true, | |
stop: function(e) { | |
$(".toggle-play").removeClass("active"); | |
$(".waves").fadeOut(); | |
}, | |
pause: function(e) { | |
$(".toggle-play").removeClass("active"); | |
$(".waves").fadeOut(); | |
}, | |
play: function(e) { | |
$(".toggle-play").addClass("active"); | |
$(".waves").fadeIn(); | |
}, | |
ready: function(e) {} | |
}); | |
$(".toggle-list").bind("click", function() { | |
if (!$("body").hasClass("active")) { | |
$("body").addClass("active"); | |
} else { | |
$("body").removeClass("active"); | |
} | |
}); | |
$(window).on("load", function() { | |
$("#jp_video").jPlayer("play"); | |
}); | |
$(".toggle-play").on("click", function() { | |
if (!$(".jp-audio").hasClass("jp-state-playing")) { | |
$("#jp_video").jPlayer("play"); | |
} else { | |
$("#jp_video").jPlayer("stop"); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jplayer/2.9.2/jplayer/jquery.jplayer.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jplayer/2.9.2/add-on/jplayer.playlist.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Player Style */ | |
.audioPlayer .jp-jplayer, #jplayer-audio-container {width: 100%;} | |
.audioPlayer .jp-controls button {text-indent: 0;} | |
.jp-audio, .jp-video {background: black;font-family: sans-serif;font-size: .75rem;margin: 0 auto;max-width: 35rem;width: 100%;} | |
.jp-type-playlist {display: -webkit-box;display: -moz-box;display: -ms-flexbox;display: -webkit-flex;display: flex;-webkit-flex-direction: column;-moz-flex-direction: column;-ms-flex-direction: column;flex-direction: column;height: 100%;} | |
.jp-type-playlist .jp-close {-webkit-flex-grow: 0;-moz-flex-grow: 0;-ms-flex-grow: 0;flex-grow: 0;} | |
.jp-type-playlist .jp-gui {-webkit-flex-grow: 0;-moz-flex-grow: 0;-ms-flex-grow: 0;flex-grow: 0;} | |
.jp-type-playlist .jp-playlist {-webkit-flex-grow: 1;-moz-flex-grow: 1;-ms-flex-grow: 1;flex-grow: 1;overflow-y: auto;} | |
.jp-btn {border: 0;padding: 0;outline: none;background: none;color: #fff;height: 1.5rem;line-height: 1.5rem;padding: 0 15px;} | |
.jp-gui {background: rgba(255, 255, 255, 0.05);padding: 1rem;} | |
.jp-gui .jp-title {display: inline-block;color: #fff;height: 1.5rem;width: 7.5rem;line-height: 1.5rem;overflow: hidden;opacity: 0.5;} | |
.jp-gui .jp-toggles {display: inline-block;float: right;} | |
.jp-gui .jp-toggles .jp-repeat, | |
.jp-gui .jp-toggles .jp-shuffle {display: inline-block;float: left;vertical-align: top;opacity: 0.5;} | |
.jp-gui .jp-times {display: -webkit-box;display: -moz-box;display: -ms-flexbox;display: -webkit-flex;display: flex;margin-top: .5rem;} | |
.jp-gui .jp-times .jp-current-time, | |
.jp-gui .jp-times .jp-duration {-webkit-flex-grow: 1;-moz-flex-grow: 1;-ms-flex-grow: 1;flex-grow: 1;color: #fff;font-size: .6rem;opacity: 0.5;} | |
.jp-gui .jp-times .jp-current-time {text-align: left;} | |
.jp-gui .jp-times .jp-duration {text-align: right;} | |
.jp-gui .jp-volume-controls {display: inline-block;float: right;} | |
.jp-gui .jp-volume-controls .jp-volume-max {display: none !important;} | |
.jp-gui .jp-volume-controls .jp-mute {display: inline-block;float: left;vertical-align: top;margin-right: -.75rem;opacity: 0.5;} | |
.jp-gui .jp-volume-controls .jp-volume-bar {display: none !important;float: left;vertical-align: top;width: 2.5rem;height: 2px;background: rgba(255, 255, 255, 0.5);margin: .65rem 0;} | |
.jp-gui .jp-volume-controls .jp-volume-bar .jp-volume-bar-value {background: #fff;height: 2px;} | |
.jp-gui .jp-controls-holder .jp-controls {padding: 1rem 0;display: -webkit-box;display: -moz-box;display: -ms-flexbox;display: -webkit-flex;display: flex;-webkit-align-items: center;-moz-align-items: center;-ms-align-items: center;align-items: center;width: 100%;} | |
.jp-gui .jp-controls-holder .jp-controls button {-webkit-flex-grow: 1;-moz-flex-grow: 1;-ms-flex-grow: 1;flex-grow: 1;height: 2.5rem;line-height: 2.5rem;} | |
.jp-gui .jp-controls-holder .jp-controls button i {font-size: 1.25rem;} | |
.jp-gui .jp-controls-holder .jp-controls button:active i {color: #09f;} | |
.jp-gui .jp-controls-holder .jp-progress .jp-seek-bar {background: rgba(255, 255, 255, 0.5);height: .15rem;} | |
.jp-gui .jp-controls-holder .jp-progress .jp-seek-bar .jp-play-bar {background: #fff;height: .15rem;} | |
.jp-state-playing .jp-play i {color: #09f;} | |
.jp-state-playing .jp-play i:before {content: "\f04c";} | |
.jp-state-looped .jp-repeat {opacity: 1 !important;} | |
.jp-state-looped .jp-repeat i {color: #09f;} | |
.jp-state-shuffled .jp-shuffle {opacity: 1 !important;} | |
.jp-state-shuffled .jp-shuffle i {color: #09f;} | |
.jp-state-muted .jp-mute {opacity: 1 !important;} | |
.jp-state-muted .jp-mute i {color: #09f;} | |
.jp-playlist {background: rgba(255, 255, 255, 0);} | |
.jp-playlist > ul {padding: 0;margin: 0;list-style: none;} | |
.jp-playlist > ul > li {display: block;padding: 0 !important;} | |
.jp-playlist > ul > li > div > a.jp-playlist-item {display: block;padding: .75rem 1rem;outline: none;color: rgba(255, 255, 255, 0.5);} | |
.jp-playlist > ul > li > div > a.jp-playlist-item.jp-playlist-current {background: rgba(255, 255, 255, 0.2);color: #fff;} | |
.jp-playlist > ul > li:nth-child(odd) > div > a {background: rgba(255, 255, 255, 0.1);} | |
.jp-gui button {background: transparent;color: #fff;} | |
.jp-interface {-webkit-align-content: center;-ms-align-content: center;align-content: center;-webkit-align-items: center;-ms-align-items: center;align-items: center;display: table;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-flex-wrap: wrap;-ms-flex-wrap: wrap;flex-wrap: wrap;justify-content: space-between;width: 100%;} | |
.jp-gui .jp-toggles {-webkit-align-content: center;-ms-align-content: center;align-content: center;-webkit-align-items: center;-ms-align-items: center;align-items: center;display: table;display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-flex-wrap: wrap;-ms-flex-wrap: wrap;flex-wrap: wrap;width: 100%;} | |
.jp-controls-holder, .jp-progress {width: 100%;} | |
.jp-seek-bar {background: rgba(255, 255, 255, 0.5);height: .15rem;} | |
.jp-play-bar {background-color: #fff;height: 100%;} | |
.jp-gui .jp-toggles button + button {margin-left: .3rem;} | |
#jp_video {height: auto !important;position: relative;padding-bottom: 54.3%;width: 100% !important;} | |
#jp_video > * {height: 100% !important;-webkit-object-fit: cover;-ms-object-fit: cover;object-fit: cover;position: absolute;width: 100% !important;} | |
.sectionContainer {padding: 3.75rem 0;} | |
.sectionContainer + .sectionContainer {border-top: .1rem solid #fff;} | |
.sectionContainer:nth-child(odd) {background-color: rgba(255, 255, 255, 0.1);} | |
.crow {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-flex-wrap: wrap;-ms-flex-wrap: wrap;flex-wrap: wrap;margin: 0 -15px;} | |
.chalf {padding: 15px;width: 50%;} | |
@media only screen and (max-width: 991px) { | |
html, body {font-size: 16px;} | |
.chalf {width: 100%;} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" /> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment