|
257 | 257 | */ |
258 | 258 | //var first = true; |
259 | 259 | var ready = false, setOder = false, first = false, open = true; |
260 | | - audioPlayer.onEvent(function (e) { |
| 260 | + if($rootScope.activePlayerEvents){ |
| 261 | + // Prevent the repetition of events by clearing all previous occurrences, as repeated events tend to occur when the user plays multiple audio files. |
| 262 | + $rootScope.activePlayerEvents.clear(); |
| 263 | + } |
| 264 | + $rootScope.activePlayerEvents = audioPlayer.onEvent(function (e) { |
261 | 265 | switch (e.event) { |
262 | 266 | case 'play': |
| 267 | + NowPlaying.currentTrack = e.data.track; |
263 | 268 | NowPlaying.playing = true; |
264 | 269 | NowPlaying.paused = false; |
265 | 270 | audioPlayer.getPlaylist(function (err, data) { |
|
322 | 327 | case 'audioEnded': |
323 | 328 | ready = false; |
324 | 329 | updateAudioMediaCount(media.id, 0.1) |
| 330 | + if(typeof $rootScope.audioFromPlayList === 'number'){ |
| 331 | + NowPlaying.playlistPause(NowPlaying.playList[$rootScope.audioFromPlayList]); |
| 332 | + return false; |
| 333 | + } |
325 | 334 | if ($rootScope.autoPlay) { |
326 | 335 | $rootScope.playNextItem(); |
327 | 336 | } else { |
|
368 | 377 | NowPlaying.playing = false; |
369 | 378 | break; |
370 | 379 | case 'next': |
371 | | - if ($rootScope.autoPlay) { |
372 | | - // param: userInput |
373 | | - $rootScope.playNextItem(true); |
374 | | - } else if (e && e.data && e.data.track) { |
375 | | - e.data.track.lastPosition = 0; |
376 | | - NowPlaying.currentTrack = e.data.track; |
377 | | - NowPlaying.playing = true; |
378 | | - } else { |
379 | | - // param: userInput |
380 | | - $rootScope.playNextItem(true); |
| 380 | + if(typeof $rootScope.audioFromPlayList === 'number'){ |
| 381 | + $rootScope.audioFromPlayList = e.data.index; |
| 382 | + NowPlaying.playList[$rootScope.audioFromPlayList].playing = true; |
| 383 | + if(!NowPlaying.settings.autoJumpToLastPosition){ |
| 384 | + audioPlayer.setTime(0); |
| 385 | + } |
| 386 | + return false; |
381 | 387 | } |
382 | 388 | break; |
383 | 389 | case 'previous': |
| 390 | + if(typeof $rootScope.audioFromPlayList === 'number' && NowPlaying.settings.autoPlayNext){ |
| 391 | + $rootScope.audioFromPlayList = e.data.index; |
| 392 | + NowPlaying.playList[$rootScope.audioFromPlayList].playing = true; |
| 393 | + audioPlayer.setTime(0); |
| 394 | + return false; |
| 395 | + } |
384 | 396 | $rootScope.playPrevItem(); |
385 | 397 | break; |
386 | 398 | case 'removeFromPlaylist': |
|
570 | 582 | audioPlayer.play(index); |
571 | 583 | } |
572 | 584 | else { |
| 585 | + $rootScope.audioFromPlayList = null; |
573 | 586 | if (isAudioEnded) { |
574 | | - console.log("Hi2") |
575 | 587 | NowPlaying.currentTrack.lastPosition = 0 |
576 | 588 | } |
577 | 589 | NowPlaying.currentTrack.url = validateURL(NowPlaying.currentTrack.url); |
|
593 | 605 | } |
594 | 606 |
|
595 | 607 |
|
596 | | - NowPlaying.playlistPlay = function (track) { |
| 608 | + NowPlaying.playlistPlay = function (track, index) { |
597 | 609 | if (NowPlaying.settings) { |
598 | 610 | NowPlaying.settings.isPlayingCurrentTrack = true; |
599 | 611 | audioPlayer.settings.set(NowPlaying.settings); |
600 | 612 | } |
601 | 613 | NowPlaying.playing = true; |
602 | | - if (track) { |
603 | | - track.url = validateURL(track.url) |
604 | | - audioPlayer.play({ url: track.url }); |
| 614 | + if (typeof index==='number') { |
| 615 | + NowPlaying.isAudioPlayerPlayingAnotherSong = false; |
| 616 | + audioPlayer.pause(); |
| 617 | + audioPlayer.play(index); |
605 | 618 | track.playing = true; |
606 | 619 | } |
607 | 620 | if (!$scope.$$phase) { |
|
650 | 663 | }; |
651 | 664 |
|
652 | 665 | NowPlaying.next = function () { |
653 | | - $rootScope.playNextItem(true); |
| 666 | + if(typeof $rootScope.audioFromPlayList === 'number'){ |
| 667 | + audioPlayer.next(); |
| 668 | + }else{ |
| 669 | + $rootScope.playNextItem(true); |
| 670 | + } |
654 | 671 | }; |
655 | 672 |
|
656 | 673 | NowPlaying.prev = function () { |
657 | | - $rootScope.playPrevItem(); |
| 674 | + if(typeof $rootScope.audioFromPlayList === 'number'){ |
| 675 | + audioPlayer.previous(); |
| 676 | + }else{ |
| 677 | + $rootScope.playPrevItem(); |
| 678 | + } |
658 | 679 | }; |
659 | 680 |
|
660 | 681 | NowPlaying.shufflePlaylist = function () { |
|
732 | 753 | NowPlaying.playList = data.tracks; |
733 | 754 | if (!$scope.$$phase) { |
734 | 755 | $scope.$digest(); |
| 756 | + if(typeof $rootScope.audioFromPlayList === 'number' ){ |
| 757 | + NowPlaying.playList[$rootScope.audioFromPlayList].playing = true; |
| 758 | + } |
735 | 759 | } |
736 | 760 | } |
737 | 761 | }); |
|
941 | 965 | } |
942 | 966 | } |
943 | 967 | else if (NowPlaying.paused) { |
| 968 | + NowPlaying.playList.forEach(element => { |
| 969 | + element.playing = false |
| 970 | + }); |
944 | 971 | if (track.url == NowPlaying.currentTrack.url) { |
945 | 972 | NowPlaying.settings.isPlayingCurrentTrack = true; |
946 | 973 | NowPlaying.playing = true; |
947 | 974 | track.playing = true; |
948 | | - audioPlayer.play(); |
| 975 | + if($rootScope.audioFromPlayList == index){ |
| 976 | + audioPlayer.play(); |
| 977 | + }else{ |
| 978 | + audioPlayer.play(index); |
| 979 | + } |
949 | 980 | } |
950 | 981 | else { |
951 | 982 | NowPlaying.playlistPlay(track, index); |
|
954 | 985 | else { |
955 | 986 | NowPlaying.playlistPlay(track, index); |
956 | 987 | } |
| 988 | + $rootScope.audioFromPlayList = index; |
957 | 989 | }; |
958 | 990 |
|
959 | 991 | /** |
|
0 commit comments