Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ new Vlitejs('#player', {
| `progress` | Sent periodically to inform interested parties of progress downloading the media. |
| `timeupdate` | Sent when the `currentTime` of the media has changed |
| `volumechange` | Sent when audio volume changes |
| `sourcechange` | Sent when source changes |
| `enterfullscreen`¹ | Sent when the video switches to fullscreen mode |
| `exitfullscreen`¹ | Sent when the video exits fullscreen mode |
| `ended` | Sent when playback completes |
Expand Down Expand Up @@ -303,6 +304,7 @@ The player instance exposes the following methods, accessible when the player is
| `getDuration()` | - | `Promise` | Get the duration |
| `mute()` | - | - | Mute the volume |
| `unMute()` | - | - | Unmute the volume |
| `setSource(source)` | `String` | - | Set the new media source |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter value info

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add note about to play trigger by this method

| `seekTo(time)` | `Number` | - | Seek to a current time in seconds |
| `requestFullscreen()` | - | - | Request the fullscreen |
| `exitFullscreen()` | - | - | Exit the fullscreen |
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"files": {
"ignoreUnknown": false,
"includes": ["**"]
"includes": ["**", "!examples/**/*.html"]
},
"formatter": {
"enabled": true,
Expand Down
4 changes: 4 additions & 0 deletions examples/audio/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '../../dist/vlite.css'
import '../../dist/plugins/volume-bar.css'
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
import Vlitejs from '../../dist/vlite.js'
import { changeSourceEvent } from '../shared/utils.js'

Vlitejs.registerPlugin('volume-bar', VlitejsVolumeBar)

Expand All @@ -24,6 +25,9 @@ new Vlitejs('#player', {
player.on('progress', () => console.log('progress'))
player.on('timeupdate', () => console.log('timeupdate'))
player.on('volumechange', () => console.log('volumechange'))
player.on('sourcechange', () => console.log('sourcechange'))
player.on('ended', () => console.log('ended'))

changeSourceEvent({ player })
}
})
1 change: 1 addition & 0 deletions examples/audio/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
</head>
<body>
<audio id="player" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-audio-html5.mp3"></audio>
<%= require('html-loader!../shared/change-source.html').default %>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/dailymotion/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../../dist/plugins/volume-bar.css'
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
import VlitejsDailymotion from '../../dist/providers/dailymotion.js'
import Vlitejs from '../../dist/vlite.js'
import { changeSourceEvent } from '../shared/utils.js'

Vlitejs.registerProvider('dailymotion', VlitejsDailymotion, {
playerId: 'x9scg'
Expand Down Expand Up @@ -35,8 +36,11 @@ new Vlitejs('#player', {
player.on('progress', () => console.log('progress'))
player.on('timeupdate', () => console.log('timeupdate'))
player.on('volumechange', () => console.log('volumechange'))
player.on('sourcechange', () => console.log('sourcechange'))
player.on('enterfullscreen', () => console.log('enterfullscreen'))
player.on('exitfullscreen', () => console.log('exitfullscreen'))
player.on('ended', () => console.log('ended'))

changeSourceEvent({ player })
}
})
3 changes: 2 additions & 1 deletion examples/dailymotion/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand All @@ -8,5 +8,6 @@
</head>
<body>
<div id="player" data-dailymotion-id="x88trc6"></div>
<%= require('html-loader!../shared/change-source.html').default %>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/html5/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import VlitejsPip from '../../dist/plugins/pip.js'
import VlitejsSubtitle from '../../dist/plugins/subtitle.js'
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
import Vlitejs from '../../dist/vlite.js'
import { changeSourceEvent } from '../shared/utils.js'

Vlitejs.registerPlugin('subtitle', VlitejsSubtitle)
Vlitejs.registerPlugin('pip', VlitejsPip)
Expand Down Expand Up @@ -55,6 +56,7 @@ new Vlitejs('#player', {
player.on('progress', () => console.log('progress'))
player.on('timeupdate', () => console.log('timeupdate'))
player.on('volumechange', () => console.log('volumechange'))
player.on('sourcechange', () => console.log('sourcechange'))
player.on('enterfullscreen', () => console.log('enterfullscreen'))
player.on('exitfullscreen', () => console.log('exitfullscreen'))
player.on('enterpip', () => console.log('enterpip'))
Expand All @@ -64,5 +66,7 @@ new Vlitejs('#player', {
player.on('ended', () => console.log('ended'))
player.on('castsessionstarted', () => console.log('castsessionstarted'))
player.on('castsessionended', () => console.log('castsessionended'))

changeSourceEvent({ player })
}
})
1 change: 1 addition & 0 deletions examples/html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<track label="English" kind="subtitles" srclang="en" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5-subtitle-en.vtt" default />
<track label="French" kind="subtitles" srclang="fr" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5-subtitle-fr.vtt" />
</video>
<%= require('html-loader!../shared/change-source.html').default %>
</body>
</html>
8 changes: 8 additions & 0 deletions examples/shared/change-source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<br />
<form class="change-source">
<fieldset>
<legend>Change media source</legend>
<input type="text" name="url" placeholder="Enter new source" value="" />
</fieldset>
<button type="submit">Submit</button>
</form>
8 changes: 8 additions & 0 deletions examples/shared/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function changeSourceEvent({ player }) {
document.querySelector('.change-source').addEventListener('submit', (e) => {
e.preventDefault()

const formData = new FormData(e.target)
player.setSource(formData.get('url'))
})
}
4 changes: 4 additions & 0 deletions examples/vimeo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../../dist/plugins/volume-bar.css'
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
import VlitejsVimeo from '../../dist/providers/vimeo.js'
import Vlitejs from '../../dist/vlite.js'
import { changeSourceEvent } from '../shared/utils.js'

Vlitejs.registerProvider('vimeo', VlitejsVimeo)
Vlitejs.registerPlugin('volume-bar', VlitejsVolumeBar)
Expand Down Expand Up @@ -34,8 +35,11 @@ new Vlitejs('#player', {
player.on('progress', () => console.log('progress'))
player.on('timeupdate', () => console.log('timeupdate'))
player.on('volumechange', () => console.log('volumechange'))
player.on('sourcechange', () => console.log('sourcechange'))
player.on('enterfullscreen', () => console.log('enterfullscreen'))
player.on('exitfullscreen', () => console.log('exitfullscreen'))
player.on('ended', () => console.log('ended'))

changeSourceEvent({ player })
}
})
1 change: 1 addition & 0 deletions examples/vimeo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
</head>
<body>
<div id="player" data-vimeo-id="162391385"></div>
<%= require('html-loader!../shared/change-source.html').default %>
</body>
</html>
4 changes: 4 additions & 0 deletions examples/youtube/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '../../dist/plugins/volume-bar.css'
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
import VlitejsYoutube from '../../dist/providers/youtube.js'
import Vlitejs from '../../dist/vlite.js'
import { changeSourceEvent } from '../shared/utils.js'

Vlitejs.registerProvider('youtube', VlitejsYoutube)
Vlitejs.registerPlugin('volume-bar', VlitejsVolumeBar)
Expand Down Expand Up @@ -34,12 +35,15 @@ new Vlitejs('#player', {
player.on('progress', () => console.log('progress'))
player.on('timeupdate', () => console.log('timeupdate'))
player.on('volumechange', () => console.log('volumechange'))
player.on('sourcechange', () => console.log('sourcechange'))
player.on('enterfullscreen', () => console.log('enterfullscreen'))
player.on('exitfullscreen', () => console.log('exitfullscreen'))
player.on('enterpip', () => console.log('enterpip'))
player.on('leavepip', () => console.log('leavepip'))
player.on('trackenabled', () => console.log('trackenabled'))
player.on('trackdisabled', () => console.log('trackdisabled'))
player.on('ended', () => console.log('ended'))

changeSourceEvent({ player })
}
})
3 changes: 2 additions & 1 deletion examples/youtube/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- CSS and JavaScript files are automatically injected by the HtmlWebpackPlugin -->
</head>
<body>
<div id="player" data-youtube-id="C4qgAaxB_pc"></div>
<div id="player" data-youtube-id="43TH3PKNc_c"></div>
<%= require('html-loader!../shared/change-source.html').default %>
</body>
</html>
93 changes: 93 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"babel-loader": "^10.0.0",
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.2",
"html-loader": "^5.1.0",
"html-webpack-plugin": "^5.6.4",
"mini-css-extract-plugin": "^2.9.4",
"postcss": "^8.5.6",
Expand Down
24 changes: 24 additions & 0 deletions src/core/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ export default abstract class Player {
*/
public abstract methodUnMute(): void

/**
* methodSetSource
* Extends by the provider
* @abstract
*/
public abstract methodSetSource(videoId: string): void

/**
* On the player is ready
*/
Expand Down Expand Up @@ -464,6 +471,23 @@ export default abstract class Player {
this.dispatchEvent('volumechange')
}

/**
* Set the new source of the player
* @param videoId Video ID
*/
setSource(videoId: string) {
// Prevent onMediaEnded to play
this.options.loop = false

this.pause()
this.onMediaEnded()
this.methodSetSource(videoId)
this.controlBar.onReady()
this.play()

this.dispatchEvent('sourcechange')
}

/**
* Update the current time of the media element
* @param newTime New current time of the media element
Expand Down
8 changes: 8 additions & 0 deletions src/providers/dailymotion/dailymotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ export default function DailymotionProvider(Player: any, options: interfaceProvi
})
}

/**
* Change source method of the player
* {@link https://developers.dailymotion.com/sdk/player-sdk/web/#player-methods}
*/
methodSetSource(id: string) {
this.instance.loadContent({ video: id })
}

/**
* Play method of the player
*/
Expand Down
Loading