Skip to content

Commit 14f493d

Browse files
committed
Add set source
1 parent 0b008b7 commit 14f493d

File tree

21 files changed

+205
-9
lines changed

21 files changed

+205
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ new Vlitejs('#player', {
269269
| `progress` | Sent periodically to inform interested parties of progress downloading the media. |
270270
| `timeupdate` | Sent when the `currentTime` of the media has changed |
271271
| `volumechange` | Sent when audio volume changes |
272+
| `sourcechange` | Sent when source changes |
272273
| `enterfullscreen`¹ | Sent when the video switches to fullscreen mode |
273274
| `exitfullscreen`¹ | Sent when the video exits fullscreen mode |
274275
| `ended` | Sent when playback completes |
@@ -303,6 +304,7 @@ The player instance exposes the following methods, accessible when the player is
303304
| `getDuration()` | - | `Promise` | Get the duration |
304305
| `mute()` | - | - | Mute the volume |
305306
| `unMute()` | - | - | Unmute the volume |
307+
| `setSource(source)` | `String` | - | Set the new media source |
306308
| `seekTo(time)` | `Number` | - | Seek to a current time in seconds |
307309
| `requestFullscreen()` | - | - | Request the fullscreen |
308310
| `exitFullscreen()` | - | - | Exit the fullscreen |

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"files": {
99
"ignoreUnknown": false,
10-
"includes": ["**"]
10+
"includes": ["**", "!examples/**/*.html"]
1111
},
1212
"formatter": {
1313
"enabled": true,

examples/audio/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import '../../dist/vlite.css'
22
import '../../dist/plugins/volume-bar.css'
33
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
44
import Vlitejs from '../../dist/vlite.js'
5+
import { changeSourceEvent } from '../shared/utils.js'
56

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

@@ -24,6 +25,9 @@ new Vlitejs('#player', {
2425
player.on('progress', () => console.log('progress'))
2526
player.on('timeupdate', () => console.log('timeupdate'))
2627
player.on('volumechange', () => console.log('volumechange'))
28+
player.on('sourcechange', () => console.log('sourcechange'))
2729
player.on('ended', () => console.log('ended'))
30+
31+
changeSourceEvent({ player })
2832
}
2933
})

examples/audio/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
</head>
99
<body>
1010
<audio id="player" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-audio-html5.mp3"></audio>
11+
<%= require('html-loader!../shared/change-source.html').default %>
1112
</body>
1213
</html>

examples/dailymotion/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import '../../dist/plugins/volume-bar.css'
33
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
44
import VlitejsDailymotion from '../../dist/providers/dailymotion.js'
55
import Vlitejs from '../../dist/vlite.js'
6+
import { changeSourceEvent } from '../shared/utils.js'
67

78
Vlitejs.registerProvider('dailymotion', VlitejsDailymotion, {
89
playerId: 'x9scg'
@@ -35,8 +36,11 @@ new Vlitejs('#player', {
3536
player.on('progress', () => console.log('progress'))
3637
player.on('timeupdate', () => console.log('timeupdate'))
3738
player.on('volumechange', () => console.log('volumechange'))
39+
player.on('sourcechange', () => console.log('sourcechange'))
3840
player.on('enterfullscreen', () => console.log('enterfullscreen'))
3941
player.on('exitfullscreen', () => console.log('exitfullscreen'))
4042
player.on('ended', () => console.log('ended'))
43+
44+
changeSourceEvent({ player })
4145
}
4246
})

examples/dailymotion/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<meta charset="utf-8" />
@@ -8,5 +8,6 @@
88
</head>
99
<body>
1010
<div id="player" data-dailymotion-id="x88trc6"></div>
11+
<%= require('html-loader!../shared/change-source.html').default %>
1112
</body>
1213
</html>

examples/html5/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import VlitejsPip from '../../dist/plugins/pip.js'
1111
import VlitejsSubtitle from '../../dist/plugins/subtitle.js'
1212
import VlitejsVolumeBar from '../../dist/plugins/volume-bar.js'
1313
import Vlitejs from '../../dist/vlite.js'
14+
import { changeSourceEvent } from '../shared/utils.js'
1415

1516
Vlitejs.registerPlugin('subtitle', VlitejsSubtitle)
1617
Vlitejs.registerPlugin('pip', VlitejsPip)
@@ -55,6 +56,7 @@ new Vlitejs('#player', {
5556
player.on('progress', () => console.log('progress'))
5657
player.on('timeupdate', () => console.log('timeupdate'))
5758
player.on('volumechange', () => console.log('volumechange'))
59+
player.on('sourcechange', () => console.log('sourcechange'))
5860
player.on('enterfullscreen', () => console.log('enterfullscreen'))
5961
player.on('exitfullscreen', () => console.log('exitfullscreen'))
6062
player.on('enterpip', () => console.log('enterpip'))
@@ -64,5 +66,7 @@ new Vlitejs('#player', {
6466
player.on('ended', () => console.log('ended'))
6567
player.on('castsessionstarted', () => console.log('castsessionstarted'))
6668
player.on('castsessionended', () => console.log('castsessionended'))
69+
70+
changeSourceEvent({ player })
6771
}
6872
})

examples/html5/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<track label="English" kind="subtitles" srclang="en" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5-subtitle-en.vtt" default />
1212
<track label="French" kind="subtitles" srclang="fr" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5-subtitle-fr.vtt" />
1313
</video>
14+
<%= require('html-loader!../shared/change-source.html').default %>
1415
</body>
1516
</html>

examples/shared/change-source.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<br />
2+
<form class="change-source">
3+
<fieldset>
4+
<legend>Change media source</legend>
5+
<input type="text" name="url" placeholder="Enter new source" value="" />
6+
</fieldset>
7+
<button type="submit">Submit</button>
8+
</form>

examples/shared/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function changeSourceEvent({ player }) {
2+
document.querySelector('.change-source').addEventListener('submit', (e) => {
3+
e.preventDefault()
4+
5+
const formData = new FormData(e.target)
6+
player.setSource(formData.get('url'))
7+
})
8+
}

0 commit comments

Comments
 (0)