RecitPlayer.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <script>
  2. import { mapActions, mapState } from 'pinia'
  3. import { ConcernementsStore } from '@stores/concernements'
  4. import { CommonStore } from '@/stores/common'
  5. export default {
  6. props: [],
  7. data() {
  8. return {
  9. plyr_options: {
  10. controls: ['play', 'progress', 'current-time', 'mute', 'volume']
  11. },
  12. fadeOutInterval: null
  13. }
  14. },
  15. computed: {
  16. ...mapState(ConcernementsStore,['opened_recit', 'recit_plyr_player']),
  17. // ...mapState(CommonStore,['hover_elmt'])
  18. },
  19. mounted() {
  20. console.log('RecitPlayer mounted', this.$refs, this.opened_recit);
  21. this.setRecitPlayer(this.$refs.plyr_player.player);
  22. this.recit_plyr_player.on('ended', ()=>{
  23. this.setOpenedRecit(null);
  24. })
  25. this.recit_plyr_player.volume = 0.6;
  26. if (this.opened_recit) {
  27. if (!this.fadeOutInterval) {
  28. this.recit_plyr_player.play();
  29. }
  30. }
  31. },
  32. watch: {
  33. opened_recit: {
  34. handler (n,o){
  35. console.log('recitPlayer watch opened_recit o, n', o, n);
  36. this.recitTransition(n,o);
  37. },
  38. deep: true
  39. }
  40. },
  41. methods: {
  42. ...mapActions(ConcernementsStore, ['setOpenedRecit', 'setRecitPlayer']),
  43. recitTransition(n, o){
  44. if(o){
  45. this.fadeOutInterval = setInterval(()=>{
  46. if (this.recit_plyr_player.volume > 0.05) {
  47. // console.log(`recitPlayer fading volume:${this.recit_plyr_player.volume}`);
  48. this.recit_plyr_player.volume *= 0.9;
  49. }else{
  50. console.log('fadeout done');
  51. this.recit_plyr_player.volume = 0.6;
  52. this.recit_plyr_player.stop();
  53. clearInterval(this.fadeOutInterval);
  54. this.fadeOutInterval = null;
  55. // if during the the fadeout we opened an other recit, play it
  56. if (this.opened_recit) {
  57. console.log('recitPlayer fade done, this.opened_recit', this.opened_recit);
  58. this.recit_plyr_player.source = {
  59. type: 'audio',
  60. sources: [
  61. {
  62. src: this.opened_recit.file.url,
  63. type: this.opened_recit.file.filemine,
  64. }
  65. ]
  66. }
  67. this.recit_plyr_player.volume = 0.6;
  68. this.recit_plyr_player.play();
  69. }
  70. }
  71. }, 1);
  72. }
  73. console.log('recitPlayer new n', n, this.fadeOutInterval);
  74. if (n && !this.fadeOutInterval) { // if new and we are not in in a fadeout
  75. if(n.file.url){
  76. // console.log(`switching source`);
  77. this.recit_plyr_player.source = {
  78. type: 'audio',
  79. sources: [
  80. {
  81. src: n.file.url,
  82. type: n.file.filemine,
  83. }
  84. ]
  85. }
  86. this.recit_plyr_player.volume = 0.6;
  87. this.recit_plyr_player.play();
  88. }
  89. }
  90. }
  91. },
  92. }
  93. </script>
  94. <template>
  95. <!-- <Transition
  96. @leave="onLeave"
  97. > -->
  98. <aside
  99. :class="{visible: opened_recit}"
  100. id="recit-player">
  101. <vue-plyr ref="plyr_player" :options="plyr_options">
  102. <audio playsinline>
  103. <source v-if="opened_recit" :src="opened_recit.file.url" :type="opened_recit.file.filemime" />
  104. </audio>
  105. </vue-plyr>
  106. </aside>
  107. <!-- </Transition> -->
  108. </template>