I have created a basic setup:
added these cdns in index.html
<link href="//amp.azure.net/libs/amp/latest/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
<script src="//amp.azure.net/libs/amp/latest/azuremediaplayer.min.js"></script>
I read the html from an external file(which I only have access to) and inject it in div inner Html and set up the players that I have on that page:
#Component({
selector: 'ss-training-page',
template: '<div [innerHtml]="content"></div>',
styleUrls: ['./training-page.component.scss']
})
export class TrainingPageComponent implements OnInit {
ngOnInit(): void {
let loading = this.loadingService.addTask();
this.route.paramMap
.take(1)
.subscribe(params => {
let page: string = params.get("page") || "";
if (page) {
this.trainingService.getPageContent(page)
.take(1)
.subscribe(res => {
this.content = this.sanitizer.bypassSecurityTrustHtml(res);
this.setupPlayer();
this.loadingService.completeTask(loading);
})
}
else {
this.loadingService.completeTask(loading);
}
},
error => {
this.notificationService.error("Error retrieving training page", error);
this.loadingService.clearAllTasks();
})
}
setupPlayer(): void {
var allVideos = Array.from(document.querySelectorAll("video"))
allVideos.forEach(v => {
var player: amp.Player;
player = amp(v.id);
player.autoplay(false);
player.controls(true);
player.src([{
src: document.getElementById(v.id).getElementsByTagName("source")[0].src,
type: "video/mp4"
}]);
})
};
}
here is an example of external html file:
<div class="row">
<div class="col-md-12">
<div class="panel panel-default b">
<div class="panel-body">
<span class="pull-right">
<button class="btn btn-square btn-primary" href="javascript:alert('This is an issue');"></button>
</span>
<div class="row">
<h1>This is a Test</h1>
<video id="vid1" class="azuremediaplayer amp-default-skin" width="640" height="400">
<source src="https://agstqaass.blob.core.net/asset-d7fd6f4e-26a7-453e-8e5e-204becae72a4/EditingABulletin.mp4?sv=2017-04-17" type="video/mp4" />
</video>
</div>
<div class="row">
<h1>This is a Test2</h1>
<video id="vid2" class="azuremediaplayer amp-default-skin" width="640" height="400">
<source src="https://agstqaass.blob.core.net/asset-d7fd6f4e-26a7-453e-8e5e-204becae72a4/EditingABulletin.mp4?sv=2017-04-17" type="video/mp4" />
</video>
</div>
</div>
</div>
</div>
</div>
this works perfectly when I load the page initially but when I navigate to somewhere else and I open the page again it shows blank black screen in video controls, kindly please help me on this.
Thanks!!!
See this question.
Call player.dispose() on every amp instance when the window is closed or when the component is destroyed.
Related
I've got 3 videos in a folder and a json file with them, I would make a list near a player, and by clicking the list item I would play that specific video on that player. I've already made html and the function to get the elements to make the list, now I have to make the function to play each video
<section class="container">
<div class="card col-sm-6">
<div class="card-body container">
<h5 class="card-title">Video</h5>
<p class="card-text">Seleziona un video in elenco per visualizzarlo</p>
<div class="row">
<div class="col-sm-6">
<ul id="listvideo" class="list-group list-group-flush border rounded">
</ul>
</div>
<div class="col-sm-6">
<video id="myVideo" src="files/assets/video/by_night.mp4" width="220"></video>
<button id="play" onclick="play()">Play</button>
<button id="stop" onclick="stop()">Stop</button>
<!-- <span id="duration"></span> -->
</div>
</div>
</div>
</div>
</section>
<script>
var myVideo = document.getElementById("myVideo");
function play() {
myVideo.play();
}
function stop(){
myVideo.pause();
}
$(document)
.ready(function() {
$.ajax({
url: 'files/assets/media.json',
method: 'GET',
dataType: "json",
success:function(data){
$.each(data.video,function(i,el){
var titolo = el.title;
console.log(titolo);
$('#listvideo').append('<li class="list-group-item"><a class="choose" href="'+el+'">'+titolo+'</a></li>');
});
}
});
$('.choose').on('click', function(e){
e.preventDefault();
var change = $(this).attr('href');
});
});
</script>
I page web aplication with index.html file where is my login page. after succes log in I want to load page with routeProvider where i am using charts to draw diagrams . I have Error when i am loading just index.html for logg in not even this page where i am using charts.
my error looks like
Error: Please set height and width for the chart element
i#http://localhost:8080/pos/js/angular-charts.min.js:1:12049
Y/<#http://localhost:8080/pos/js/angular.min.js:70:91
Z#http://localhost:8080/pos/js/angular.min.js:70:149
A#http://localhost:8080/pos/js/angular.min.js:59:203
g#http://localhost:8080/pos/js/angular.min.js:51:299
g#http://localhost:8080/pos/js/angular.min.js:51:316
g#http://localhost:8080/pos/js/angular.min.js:51:316
g#http://localhost:8080/pos/js/angular.min.js:51:316
F/<#http://localhost:8080/pos/js/angular.min.js:50:415
ngViewFillContentFactory/<.link#http://localhost:8080/pos/js/angular-route.js:983:7
Z#http://localhost:8080/pos/js/angular.min.js:70:149
A#http://localhost:8080/pos/js/angular.min.js:59:203
g#http://localhost:8080/pos/js/angular.min.js:51:299
F/<#http://localhost:8080/pos/js/angular.min.js:50:415
I/<#http://localhost:8080/pos/js/angular.min.js:52:283
l#http://localhost:8080/pos/js/angular.min.js:56:293
update#http://localhost:8080/pos/js/angular-route.js:933:25
Pe/this.$get</l.prototype.$broadcast#http://localhost:8080/pos/js/angular.min.js:128:120
commitRoute/<#http://localhost:8080/pos/js/angular-route.js:616:15
f/<#http://localhost:8080/pos/js/angular.min.js:112:20
Pe/this.$get</l.prototype.$eval#http://localhost:8080/pos/js/angular.min.js:125:301
Pe/this.$get</l.prototype.$digest#http://localhost:8080/pos/js/angular.min.js:122:390
Pe/this.$get</l.prototype.$apply#http://localhost:8080/pos/js/angular.min.js:126:56
l#http://localhost:8080/pos/js/angular.min.js:81:169
S#http://localhost:8080/pos/js/angular.min.js:85:301
vf/</D.onload#http://localhost:8080/pos/js/angular.min.js:86:315
<div data-ac-chart="'pie'" data-ac-data="cityData" data-ac-config="cityConf" class="chart ng-isolate-scope" id="chart">
here is my html file where i have charts
<div class="row-fluid maginTopDiv">
<div class="span4">
<h2>City</h2>
<div
data-ac-chart="'pie'"
data-ac-data="cityData"
data-ac-config="cityConf"
class="chart" id="chart">
</div>
</div>
<div class="span4">
<h2>Type</h2>
<div
data-ac-chart="'pie'"
data-ac-data="termTypeData"
data-ac-config="termTypeConf"
class="chart" id="chart">
</div>
</div>
<div class="span4">
<h2>Program ID</h2>
<div
data-ac-chart="'pie'"
data-ac-data="programIdData"
data-ac-config="programIdConf"
class="chart" id="chart">
</div>
</div>
</div>
here is my css content for this divs
.chart{
width: 100%;
height: 200px;
}
my config for routing
app.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'home.htm',
controller: 'mainController'
})
.when('/dashboard', {
templateUrl: 'home.htm',
controller: 'mainController'
})
.when('/archive',{
templateUrl: 'problemArchive.htm',
controller: 'mainController'
})
.otherwise({
templateUrl: 'home.htm',
controller: 'mainController'
});
});
and in controller i am defining data for this charts after successuly logg in and after login i am getting data on the page except this charts.
why i have this errors when i even not loading this page i just have index.html page where i am not using charts, just after log in
This is my first time using ui-router and I find difficulties in handling routing and reloading some states. I hope anyone can help me with this.
overview of my index.html
<html ng-app="resApp">
<head></head>
<body ng-controller="mainCtrl" ng-cloak>
<div ng-show="showCustomerContent">
<div id="page-wrapper">
<div ui-view="header"></div>
<div ui-view="slider" ng-show="displaySlider"></div>
<div ui-view="content"></div>
<div ui-view="footer"></div>
</div>
</div>
<div ng-show="showAdminContent">
<div id="page-wrapper">
<div ui-view="aheader"></div>
<div ui-view="asidebar"></div>
<div id="page-content-wrapper">
<div id="page-content">
<div class="container-fluid">
<div ui-view="acontent"></div>
</div>
</div>
</div>
<div ui-view="jsincludes"></div>
</body>
</html>
routing.js
'use strict'
resApp.config(['$stateProvider', '$urlRouterProvider','$httpProvider','$locationProvider',function ($stateProvider, $urlRouterProvider, $httpProvider,$locationProvider) {
$urlRouterProvider
.when('/','/Home')
.when('/login','/Home')
.otherwise('/Home');
$stateProvider
.state("home",{
url:'/Home',
views:{
'jsincludes':{
templateUrl:'views/includes/jsincludes.html'
},
'header':{
templateUrl:'views/customer_part/header.html',
controller:'headerCtrl'
},
'slider':{
templateUrl:'views/customer_part/slider.html'
},
'footer':{
templateUrl:'views/customer_part/footer.html'
}
}
})
.state("home.aboutus",{
url:"/AboutUs",
views:{
'content#':{
templateUrl:'views/customer_views/aboutus.html',
controller:'aboutusCtrl'
}
}
})
$httpProvider.useApplyAsync(true);
}]);
controller.js
'use strict'
resApp.controller('mainCtrl',['$scope','$location','UserData','$rootScope',function($scope,$location,UserData,$rootScope){
$rootScope.displaySlider = true;
$scope.$on('$stateChangeSuccess',function(event, toState){
var url = $location.absUrl().split('/');
//console.log(url);
if(url.length > 6){
$rootScope.displaySlider = false;
}else{
$rootScope.displaySlider = true;
}
});
UserData.getSessVar().then(function(msg){
if(msg.data!="none"){
$rootScope.uid = msg.data["uid"];
$rootScope.fullname = msg.data["fullname"];
$rootScope.role = msg.data["role"];
$rootScope.Id = msg.data["Id"];
if($rootScope.role == "customer"){
$scope.showCustomerContent = true;
}else{
$scope.showAdminContent = true;
}
}else{
$rootScope.role = "none";
$scope.showCustomerContent = true;
}
});
}]);
resApp.controller('headerCtrl',['$scope','$rootScope','UserData','$location','$state','$stateParams',function($scope,$rootScope,UserData,$location,$state,$stateParams){
$scope.hideLoginBtn = false;
if($rootScope.uid!=undefined){
$scope.hideLoginBtn = true;
}
$scope.logout = function(){
UserData.logoutUser($rootScope.Id).then(function(msg){
if(msg.data=="success"){
window.location.reload();
//$location.path('/Home');
}
});
}
$scope.home = function(){
$state.go('home', {}, { reload: true });
}
$scope.aboutus = function(){
$state.go('home.aboutus',{},{reload:true});
}
}]);
resApp.controller('aheaderCtrl',['$scope','$rootScope','UserData','$location',function($scope,$rootScope,UserData,$location){
$scope.logout = function(){
UserData.logoutUser($rootScope.Id).then(function(msg){
if(msg.data=="success"){
window.location.reload();
//$location.path('/Home');
}
});
}
}]);
In my header.html I have this code
<li>
<a href="" title="Home" ng-click="home()">
Home
</a>
</li>
Whenever I click Home the index.html is displaying another copy of my header and slider. As you can see in the image the {{fullname}} scope was displayed and also the other ui-views. I tried doing the ui-sref="home" ui-sref-opts="{reload: true, notify: true}" and put it in my anchor tag but the result is the same. I need to reload the page because my slider is not displaying if I just do ui-sref="home". I also tried to use the ng-cloak but whenever I click the anchor tag it also display my raw code in angularjs. The displayed raw code disappear when the whole page was rendered. Can anyone help me with this?
Update
This error only appeared in mozilla firefox. My routing is perfectly fine in chrome
There is div tag closing issue on the below code
<div ng-show="showAdminContent">
<div id="page-wrapper">
<div ui-view="aheader"></div>
<div ui-view="asidebar"></div>
<div id="page-content-wrapper">
<div id="page-content">
<div class="container-fluid">
<div ui-view="acontent"></div>
</div>
</div>
</div>
Change it as below
<div ng-show="showAdminContent">
<div id="page-wrapper">
<div ui-view="aheader"></div>
<div ui-view="asidebar"></div>
<div id="page-content-wrapper">
<div id="page-content">
<div class="container-fluid">
<div ui-view="acontent"></div>
</div>
</div>
</div>
</div>
Also, I am not sure why are you keeping header, footer, and slider as a named ui-view while you can achieve the same using simple ng-include. Use routing only for redirection and hyperlinks.
Refer my plunker for how to do it
https://plnkr.co/edit/ZatFwz83ODsPjy55eRc5?p=preview
Ideally you should have another html file ex:- main.html and in main.html specify the ui-view. for ex:-
<div id="wrapper">
<div ui-view="header"></div>
<div ui-view></div>
<div ui-view="footer"></div>
Hi so I am working on a project and am making a custom video player I used this website to help make it http://www.inwebson.com/demo/html5-video/demo1/. So my problem is that the controls will go full screen fine but the video stays its original size in the middle with black filling the rest of the screen.
Here is my full screen code:
$('.buttonFullscreen').on('click', function() {
$(this).toggleClass('enterFullscreenBtn');
if ($.isFunction(video[0].webkitEnterFullscreen)) {
if ($(this).hasClass("enterFullscreenBtn")) {
document.getElementById('videoContainer').webkitRequestFullScreen();
} else {
document.webkitCancelFullScreen();
}
} else if ($.isFunction(video[0].mozRequestFullScreen)) {
if ($(this).hasClass("enterFullscreenBtn")) {
document.getElementById('videoContainer').mozRequestFullScreen();
} else {
document.mozCancelFullScreen();
}
} else {
alert('Your browsers doesn\'t support fullscreen');
}
});
and here is my video and controls code:
<div id="videoContainer" width='{{width}}' height='{{height}}'>
<video id='{{videoContainerID}}-video' class='{{videoID}}' controls poster='{{thumbnailURL}}' width="100%">
<source src='{{videoURL}}' type='video/mp4'></source>
<p class='hlplayer-unsupported-player'>Your browser is not supported by this player. This video player is still in development.</p>
</video>
<div class='hlplayer-video-title'>{{title}}</div>
<div class='controls'>
<div class='top-bar-controls' width='{{width}}'>
<div class='progress'>
<span class='buffer-bar'></span>
<span class='time-bar'></span>
</div>
<div class='time'>
<span class='current'></span> / <span class='duration'></span>
</div>
</div>
<div class='bottom-bar-controls' width='{{width}}'>
<div class='buttonPlay button' title='Play/Pause'></div>
<div class='buttonSettings button' title='Settings'></div>
<div class='buttonNotes button' title='Take Notes'></div>
<div class='buttonLight lighton button' title='Light On/Off'></div>
<div class='buttonFullscreen button' title='Fullscreen'></div>
<div class='volume' title='Volume'>
<span class='volume-bar'></span>
</div>
<div class='sound sound2 button' title='Mute/Unmute'></div>
</div>
</div>
<div class='loading'></div>
<div class='hlplayer-settings'>
<label class='settings-checkbox-label'><input class='settings-checkbox' id="show-notes-checkbox" type='checkbox' name='notes' checked></input> Show Notes</label>
</div>
</div>
Can you think of why this is happening? Thanks in advance.
<div id="video-container">
<!-- Video -->
<video id="video" width="640" height="365">
<source src="videos/mikethefrog.webm" type="video/webm">
<source src="videos/mikethefrog.ogv" type="video/ogv">
<source src="videos/mikethefrog.mp4" type="video/mp4">
<p>
Your browser doesn't support HTML5 video.
Download the video instead.
</p>
</video>
<!-- Video Controls -->
<div id="video-controls">
<button type="button" id="full-screen">Full-Screen</button>
</div>
</div>
fullScreenButton.addEventListener("click", function() {
if (video.requestFullscreen) {
video.requestFullscreen();
} else if (video.mozRequestFullScreen) {
video.mozRequestFullScreen(); // Firefox
} else if (video.webkitRequestFullscreen) {
video.webkitRequestFullscreen(); // Chrome and Safari
}
});
Or you can use the following:
<script>
var videoElement = document.getElementById("myvideo");
function toggleFullScreen() {
if (!document.mozFullScreen && !document.webkitFullScreen) {
if (videoElement.mozRequestFullScreen) {
videoElement.mozRequestFullScreen();
} else {
videoElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else {
document.webkitCancelFullScreen();
}
}
}
If none of these work, just use a different player. There are plenty out there that work :).
I am trying to have two files in one HTML 5 Audio Tag that play one after the other. The code I have so far is:
<audio id="ListenLive" controls autoplay>
<source src="advert.mp3" type="audio/mpeg">
<source src="stream.mp3" type="audio/mpeg">
</audio>
The issue I am having at the moment is that only the first file will play and end, it is like there is no second file. As soon as the first song ends it does nothing else.
Is there a way to get the second track to play automatically when the first one ends? I need it to be in HTML as it is for a mobile site so some code may not work on some devices
In javascript you can do it like this (this is just to get you started):
audio = new Audio("start url");
audio.addEventListener('ended',function(){
audio.src = "new url";
audio.pause();
audio.load();
audio.play();
});
if you want you can also use the same player(jquery):
var audio = $("#player");
Adding multiple sources to tag doesn't work this way. You can use it to providing the source in multiple formats.(some browsers don't support mp3 - i.e. Firefox doesn't support mp3 and you should provide ogg file)
Sample:
<audio>
<source src="" id="oggSource" type="audio/ogg" />
<source src="" id="mp3Source" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
Your case is different. You are trying to make a playlist. You can make a playlist by yourself or simply use third party plugins like:
http://www.jplayer.org/latest/demo-02-jPlayerPlaylist/
Using jPlayer would solve the browser compatibility issue too. For instance if you just provide .mp3 format, it will switch to flash version when user is browsing with Firefox.
With some javascript you can do a trick
Here is an sample, another one
jQuery(function($) {
var supportsAudio = !!document.createElement('audio').canPlayType;
if(supportsAudio) {
var index = 0,
playing = false;
mediaPath = 'http://jonhall.info/how_to/assets/media/audio/',
extension = '',
tracks = [
{"track":1,"name":"Happy Birthday Variation: In the style of Beethoven","length":"00:55","file":"01_Happy_Birthday_Variation_In_The"},
{"track":2,"name":"Wedding March Variation 1","length":"00:37","file":"02_Wedding_March_1"},
{"track":3,"name":"Happy Birthday Variation: In the style of Tango","length":"01:05","file":"03_Happy_Birthday_Variation_In_The"},
{"track":4,"name":"Wedding March Variation 2","length":"00:40","file":"04_Wedding_March_2"},
{"track":5,"name":"Random Classical","length":"00:59","file":"05_AFI_com"}
],
trackCount = tracks.length,
npAction = $('#npAction'),
npTitle = $('#npTitle'),
audio = $('#audio1').bind('play', function() {
playing = true;
npAction.text('Now Playing:');
}).bind('pause', function() {
playing = false;
npAction.text('Paused:');
}).bind('ended', function() {
npAction.text('Paused:');
if((index + 1) < trackCount) {
index++;
loadTrack(index);
audio.play();
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}).get(0),
btnPrev = $('#btnPrev').click(function() {
if((index - 1) > -1) {
index--;
loadTrack(index);
if(playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
btnNext = $('#btnNext').click(function() {
if((index + 1) < trackCount) {
index++;
loadTrack(index);
if(playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
li = $('#plUL li').click(function() {
var id = parseInt($(this).index());
if(id !== index) {
playTrack(id);
}
}),
loadTrack = function(id) {
$('.plSel').removeClass('plSel');
$('#plUL li:eq(' + id + ')').addClass('plSel');
npTitle.text(tracks[id].name);
index = id;
audio.src = mediaPath + tracks[id].file + extension;
},
playTrack = function(id) {
loadTrack(id);
audio.play();
};
extension = audio.canPlayType('audio/mpeg') ? '.mp3' : audio.canPlayType('audio/ogg') ? '.ogg' : '';
loadTrack(index);
}
$('#useLegend').click(function(e) {
e.preventDefault();
$('#use').slideToggle(300, function() {
$('#useSpanSpan').text(($('#use').css('display') == 'none' ? 'show' : 'hide'));
});
});
});
<link href="http://jonhall.info/examples/html5_audio_playlist_example.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="content" role="main">
<div id="cwrap">
<div id="nowPlay" class="is-audio">
<h3 id="npAction">Paused:</h3>
<div id="npTitle"></div>
</div>
<div id="audiowrap">
<div id="audio0">
<audio id="audio1" controls="controls">
Your browser does not support the HTML5 Audio Tag.
</audio>
</div>
<noscript>Your browser does not support JavaScript or JavaScript has been disabled. You will need to enable JavaScript for this page.</noscript>
<div id="extraControls" class="is-audio">
<button id="btnPrev" class="ctrlbtn">|<< Prev Track</button> <button id="btnNext" class="ctrlbtn">Next Track >>|</button>
</div>
</div>
<div id="plwrap" class="is-audio">
<div class="plHead">
<div class="plHeadNum">#</div>
<div class="plHeadTitle">Title</div>
<div class="plHeadLength">Length</div>
</div>
<div class="clear"></div>
<ul id="plUL">
<li class="plItem">
<div class="plNum">1</div>
<div class="plTitle">Happy Birthday Variation: In the style of Beethoven</div>
<div class="plLength">0:55</div>
</li>
<li class="plItem">
<div class="plNum">2</div>
<div class="plTitle">Wedding March Variation 1</div>
<div class="plLength">0:37</div>
</li>
<li class="plItem">
<div class="plNum">3</div>
<div class="plTitle">Happy Birthday Variation: In the style of Tango</div>
<div class="plLength">1:05</div>
</li>
<li class="plItem">
<div class="plNum">4</div>
<div class="plTitle">Wedding March Variation 2</div>
<div class="plLength">0:40</div>
</li>
<li class="plItem">
<div class="plNum">5</div>
<div class="plTitle">Random Classical</div>
<div class="plLength">0:59</div>
</li>
</ul>
</div>
</div>
</div>
HTML5 audio player, event driven and multiple track.
Thanks to jonhall.info and Thirumalai murugan to provide example.
jQuery(function($) {
var supportsAudio = !!document.createElement('audio').canPlayType;
if(supportsAudio) {
var index = 0,
playing = false,
tracks = [
{"track":1,"name":"SoundHelix Song 1","length":"06:12","file":"https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"},
{"track":2,"name":"SoundHelix Song 3","length":"05:44","file":"https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"},
{"track":3,"name":"SoundHelix Song 8","length":"05:25","file":"https://www.soundhelix.com/examples/mp3/SoundHelix-Song-8.mp3"}
],
trackCount = tracks.length,
npAction = $('#npAction'),
npTitle = $('#npTitle'),
audio = $('#audio1').bind('play', function() {
playing = true;
npAction.text('Now Playing:');
}).bind('pause', function() {
playing = false;
npAction.text('Paused:');
}).bind('ended', function() {
npAction.text('Paused:');
if((index + 1) < trackCount) {
index++;
loadTrack(index);
audio.play();
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}).get(0),
btnPrev = $('#btnPrev').click(function() {
if((index - 1) > -1) {
index--;
loadTrack(index);
if(playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
btnNext = $('#btnNext').click(function() {
if((index + 1) < trackCount) {
index++;
loadTrack(index);
if(playing) {
audio.play();
}
} else {
audio.pause();
index = 0;
loadTrack(index);
}
}),
loadTrack = function(id) {
$('.plSel').removeClass('plSel');
$('#plTrack>div:eq(' + id + ')').addClass('plSel');
npTitle.text(tracks[id].name);
index = id;
audio.src = tracks[id].file;
},
displayTrack = function(){
var parent = $('#plTrack');
$.each(tracks, function(i, track) {
$('<div></div>').addClass('row')
.append($('<div></div>').addClass('col-sm').text(track.track))
.append($('<div></div>').addClass('col-sm').text(track.name))
.append($('<div></div>').addClass('col-sm').text(track.length))
.appendTo(parent);
});
},
playTrack = function(id) {
loadTrack(id);
audio.play();
};
displayTrack();
loadTrack(index);
}
});
#plTrack .plSel {
font-weight: bold;
}
.header {
color: #999;
border-bottom: 1px solid #999;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<div>
<div class="row">
<div class="col-6"><h3 id="npAction">Paused:</h3></div>
<div class="col-6" id="npTitle"></div>
</div>
<div class="row">
<div class="col-6">
<audio id="audio1" controls="controls">
Your browser does not support the HTML5 Audio Tag.
</audio>
</div>
<noscript>Your browser does not support JavaScript or JavaScript has been disabled. You will need to enable JavaScript for this page.</noscript>
<div class="col-6">
<button id="btnPrev" class="ctrlbtn">|<< Prev Track</button> <button id="btnNext" class="ctrlbtn">Next Track >>|</button>
</div>
</div>
<div>
<div class="row header">
<div class="col-sm">#</div>
<div class="col-sm">Title</div>
<div class="col-sm">Length</div>
</div>
<div id="plTrack"></div>
</div>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h2>Welcome To GFG</h2>
<div>
<h2>Set up multiple media resources for audios:</h2>
<audio controls id="listenLive1">
<source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-4.mp3" type="audio/mpeg">
</audio>
<br><br>
<audio controls id="listenLive2">
<source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-15.mp3" type="audio/mpeg">
</audio>
</div>
</body>
</html>
By adding more "<audio>" tags you can add more audio players in the browser using HTML5...