viewYoutubeVideo.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { defineStore } from "pinia";
  2. export const useViewYoutubeVideoStore = props => {
  3. const { modalUuid } = props;
  4. return defineStore(`viewYoutubeVideo-${modalUuid}`, {
  5. state: () => ({
  6. videoId: null,
  7. youtubeId: null,
  8. video: {},
  9. player: {
  10. error: false,
  11. errorMessage: "",
  12. player: null,
  13. paused: true,
  14. playerReady: false,
  15. autoPlayed: false,
  16. duration: "0.000",
  17. currentTime: 0,
  18. playbackRate: 1,
  19. videoNote: "",
  20. volume: 0,
  21. muted: false,
  22. showRateDropdown: false
  23. }
  24. }),
  25. actions: {
  26. init({ videoId, youtubeId }) {
  27. this.videoId = videoId;
  28. this.youtubeId = youtubeId;
  29. },
  30. viewYoutubeVideo(video) {
  31. this.videoId = this.videoId || video._id;
  32. this.youtubeId = video.youtubeId || video.youtubeId;
  33. this.video = video;
  34. },
  35. updatePlayer(player) {
  36. this.player = Object.assign(this.player, player);
  37. },
  38. stopVideo() {
  39. if (this.player.player && this.player.player.pauseVideo) {
  40. this.player.player.pauseVideo();
  41. this.player.player.seekTo(0);
  42. }
  43. },
  44. loadVideoById(id) {
  45. this.player.player.loadVideoById(id);
  46. },
  47. pauseVideo(status) {
  48. if (
  49. (this.player.player && this.player.player.pauseVideo) ||
  50. this.player.playVideo
  51. ) {
  52. if (status) this.player.player.pauseVideo();
  53. else this.player.player.playVideo();
  54. }
  55. this.player.paused = status;
  56. },
  57. setPlaybackRate(rate) {
  58. if (rate) {
  59. this.player.playbackRate = rate;
  60. this.player.player.setPlaybackRate(rate);
  61. } else if (
  62. this.player.player.getPlaybackRate() !== undefined &&
  63. this.player.playbackRate !==
  64. this.player.player.getPlaybackRate()
  65. ) {
  66. this.player.player.setPlaybackRate(
  67. this.player.playbackRate
  68. );
  69. this.player.playbackRate =
  70. this.player.player.getPlaybackRate();
  71. }
  72. }
  73. }
  74. })();
  75. };