Skip to content

Commit

Permalink
Merge pull request #12 from mindvalley/emit-error
Browse files Browse the repository at this point in the history
Emit videojs error
  • Loading branch information
amitchaudhary140 authored Jul 31, 2023
2 parents fbd9cf9 + 64f896d commit 7669758
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The components are grouped in below categories. Each category has its own reason
- Carousel
- **Utils**
- Browser Detection
- Format Sources

_Important_: When above components are consumed, they are used with **MV** prefix. It means, **AudioPlayer** becomes **MVAudioPlayer**.

Expand Down Expand Up @@ -123,6 +124,7 @@ This component represents the _virtual_ instance of a player. It means, that all
@rewind="emitEvent('rewind', $event)"
@fastforward="emitEvent('fastforward', $event)"
@playbackSpeed="emitEvent('playbackSpeed', $event)"
@error="emitEvent('error', $event)"
>
<!-- Other code -->
Expand Down Expand Up @@ -491,6 +493,7 @@ You can think of this component as an extension to _AudioItem_ component because
@fastforward="logEvent('fastforward', $event)"
@playbackSpeed="logEvent('playbackSpeed', $event)"
@favourite="logEvent('favourite', $event)"
@error="logEvent('error', $event)"
>
<!-- Other code-->
Expand Down Expand Up @@ -555,6 +558,10 @@ _**Usage**_
<MVMeditationTrackItem
:sources="formatSources(sound?.item?.mediaAsset.renditions)"
:background-src="sound?.item?.coverAsset?.thumbnailUrl"
@play="logEvent('play', $event)"
@pause="logEvent('pause', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
/>
</MVCarouselSlide>
</MVCarousel>
Expand Down Expand Up @@ -617,6 +624,33 @@ It exposes below properties:
- isiPad
- isTouchDevice

Usage:

```
import { useDetectBrowser } from "@mindvalley/mv-universal-player";
const { isiPhone, isiPad, isiPhoneOriPadSafari } = useDetectBrowser();
```

**useGlobal**

This composable clubs generic utitlity features. For example, it includes **formatSources** method to help format and priotize _.hls_ (for video) and _.mp4a_ (for audio) sources. So, let's say you pass a list of renditions which has _.mp4a_ as source, then this will be the _only_ source that would be considered. If not, then rest of the sources will be considered as fallback.

Usage:

```
import { useGlobal } from "@mindvalley/mv-universal-player";
const { formatSources } = useGlobal();
```

_formatSources_ accepts two parameters:

| Name | Type | Default | Description |
| ------- | ------------------------------------------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------- |
| sources | [{id: string, contentType: string, url: string}] | [] | The list of sources which contains renditions. |
| isAudio | boolean | true | It is to identify whether the sources are of audio or video. For audio '.mp4a' is considered as priority and for video, .hls. |

## Package Configuration

**Vue Version Support**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mindvalley/mv-universal-player",
"version": "1.0.8",
"version": "1.0.10",
"author": {
"name": "Mindvalley"
},
Expand Down
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@playbackSpeed="logEvent('playbackSpeed', $event)"
@favourite="logEvent('favourite', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
>
<template #audio-description>
<MVAudioDescription
Expand Down Expand Up @@ -56,6 +57,7 @@
@play="logEvent('play', $event)"
@pause="logEvent('pause', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
/>
</MVCarouselSlide>
</MVCarousel>
Expand Down
12 changes: 12 additions & 0 deletions src/components/audio/AudioItem/AudioItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,21 @@ const emit = defineEmits<{
(e: 'rewind', { previousTime, currentTime }: any): void
(e: 'fastforward', { previousTime, currentTime }: any): void
(e: 'reset', { currentTime }: any): void
(e: 'error', payload: any): void
(e: any, payload: any): void
}>()
watch(
() => audioState.value.error,
(error) => {
if (props.id === audioState.value.audioItemId) {
if (error) {
emit('error', error)
}
}
}
)
watch(
[() => audioState.value.playing, () => audioState.value.audioItemId],
([newPlaying, newAudioItemId]) => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/audio/AudioResource/AudioResource.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const Default: Story = {
@playbackSpeed="logEvent('playbackSpeed', $event)"
@favourite="logEvent('favourite', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
></MVAudioResource></MVAudioPlayer></div>`
}),
args: {
Expand Down Expand Up @@ -195,6 +196,7 @@ export const WithDescription: Story = {
@playbackSpeed="logEvent('playbackSpeed', $event)"
@favourite="logEvent('favourite', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
>
<template #audio-description>
Expand Down Expand Up @@ -254,6 +256,7 @@ export const WithMeditationMixer: Story = {
@playbackSpeed="logEvent('playbackSpeed', $event)"
@favourite="logEvent('favourite', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
>
<template #audio-description>
Expand Down Expand Up @@ -282,6 +285,7 @@ export const WithMeditationMixer: Story = {
@play="logEvent('play', $event)"
@pause="logEvent('pause', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
/>
</MVCarouselSlide>
</MVCarousel>
Expand Down Expand Up @@ -342,6 +346,7 @@ export const MultipleAudios: Story = {
@favourite="logEvent('favourite', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@reset="logEvent('reset', $event)"
@error="logEvent('error', $event)"
>
<template #audio-description>
Expand Down Expand Up @@ -370,6 +375,7 @@ export const MultipleAudios: Story = {
@play="logEvent('play', $event)"
@pause="logEvent('pause', $event)"
@timeupdate="logEvent('timeupdate', $event)"
@error="logEvent('error', $event)"
/>
</MVCarouselSlide>
</MVCarousel>
Expand Down
2 changes: 2 additions & 0 deletions src/components/audio/AudioResource/AudioResource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const emit = defineEmits<{
(e: 'rewind', { previousTime, currentTime }: any): void
(e: 'fastforward', { previousTime, currentTime }: any): void
(e: 'reset', { currentTime }: any): void
(e: 'error', payload: any): void
(e: any, payload: any): void
}>()
Expand Down Expand Up @@ -109,6 +110,7 @@ const handleFavourite = () => {
@playbackSpeed="emitEvent('playbackSpeed', $event)"
@timeupdate="emitEvent('timeupdate', $event)"
@reset="emitEvent('reset', $event)"
@error="emitEvent('error', $event)"
>
<div class="grid grid-cols-3 text-white relative gap-8">
<!-- Image -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const emit = defineEmits<{
(e: 'play', { currentTime }: any): void
(e: 'pause', { currentTime }: any): void
(e: 'ended', { currentTime }: any): void
(e: 'error', payload: any): void
(e: any, payload: any): void
}>()
Expand Down Expand Up @@ -132,6 +133,7 @@ const emitEvent = (eventName: string, payload?: any) => {
@pause="emitEvent('pause', $event)"
@timeupdate="emitEvent('timeupdate', $event)"
@ended="emitEvent('ended', $event)"
@error="emitEvent('error', $event)"
>
<div
data-testid="meditation-track-item"
Expand Down
14 changes: 6 additions & 8 deletions src/composables/use-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@ export function useGlobal() {
return secMin
}

const formatSources = (localSources: any = [], isAudio = true) => {
const formatSources = (sources: any = [], isAudio = true) => {
const hlsId = isAudio ? 'mp4a' : 'hls'
let audioSources = []

if (localSources && localSources.length) {
audioSources = localSources?.filter((source: any) => source.id === hlsId)
if (sources && sources.length) {
audioSources = sources?.filter((source: any) => source.id === hlsId)
}

if (!audioSources.length) {
audioSources = localSources?.filter(
(source: any) => source.id === 'mp3' || source.id === 'ogg'
)
audioSources = sources?.filter((source: any) => source.id === 'mp3' || source.id === 'ogg')
}

const updatedSources = []

for (const i in audioSources) {
updatedSources.push({
type: localSources[i]?.contentType,
src: localSources[i]?.url
type: sources[i]?.contentType,
src: sources[i]?.url
})
}

Expand Down

0 comments on commit 7669758

Please sign in to comment.