@@ -45,9 +45,13 @@ function createManager() {
4545}
4646const manager = createManager ( ) ;
4747
48- function skipIfAutoplay ( player , playerVars ) {
49- if ( playerVars . autoplay != undefined &&
50- playerVars . autoplay == YT . AutoPlay . AutoPlay ) {
48+ /**
49+ * seekIfAutoplay seeks to the provided timestamp if autoplay is enabled
50+ * @param player The player instance
51+ * @param playerVars The player vars
52+ */
53+ function seekIfAutoplay ( player , playerVars ) {
54+ if ( playerVars . autoplay != undefined && playerVars . autoplay == YT . AutoPlay . AutoPlay ) {
5155 player . mute ( ) ;
5256 if ( playerVars . start != undefined && playerVars . start != 0 ) {
5357 player . seekTo ( playerVars . start , true ) ;
@@ -58,7 +62,7 @@ function skipIfAutoplay(player, playerVars) {
5862 }
5963}
6064
61- const player = {
65+ const player = vue . defineComponent ( {
6266 name : 'YoutubeIframe' ,
6367 props : {
6468 playerWidth : {
@@ -96,23 +100,131 @@ const player = {
96100 return vue . h ( 'div' , [ vue . h ( 'div' , { id : this . elementId } ) ] ) ;
97101 } ,
98102 template : '<div><div :id="elementId"></div></div>' ,
103+ methods : {
104+ cueVideoById ( videoId , startSeconds , suggestedQuality ) {
105+ this . player . cueVideoById ( videoId , startSeconds , suggestedQuality ) ;
106+ } ,
107+ loadVideoById ( videoId , startSeconds , suggestedQuality ) {
108+ this . player . loadVideoById ( videoId , startSeconds , suggestedQuality ) ;
109+ } ,
110+ cueVideoByUrl ( mediaContentUrl , startSeconds , suggestedQuality ) {
111+ this . player . cueVideoByUrl ( mediaContentUrl , startSeconds , suggestedQuality ) ;
112+ } ,
113+ loadVideoByUrl ( mediaContentUrl , startSeconds , suggestedQuality ) {
114+ this . player . loadVideoByUrl ( mediaContentUrl , startSeconds , suggestedQuality ) ;
115+ } ,
116+ cuePlaylist ( playlist , index , startSeconds , suggestedQuality ) {
117+ this . player . cuePlaylist ( playlist , index , startSeconds , suggestedQuality ) ;
118+ } ,
119+ loadPlaylist ( playlist , index , startSeconds , suggestedQuality ) {
120+ this . player . loadPlaylist ( playlist , index , startSeconds , suggestedQuality ) ;
121+ } ,
122+ playVideo ( ) {
123+ this . player . playVideo ( ) ;
124+ } ,
125+ pauseVideo ( ) {
126+ this . player . pauseVideo ( ) ;
127+ } ,
128+ stopVideo ( ) {
129+ this . player . stopVideo ( ) ;
130+ } ,
131+ seekTo ( seconds , allowSeekAhead ) {
132+ this . player . seekTo ( seconds , allowSeekAhead ) ;
133+ } ,
134+ nextVideo ( ) {
135+ this . player . nextVideo ( ) ;
136+ } ,
137+ previousVideo ( ) {
138+ this . player . previousVideo ( ) ;
139+ } ,
140+ playVideoAt ( index ) {
141+ this . player . playVideoAt ( index ) ;
142+ } ,
143+ mute ( ) {
144+ this . player . mute ( ) ;
145+ } ,
146+ unMute ( ) {
147+ this . player . unMute ( ) ;
148+ } ,
149+ isMuted ( ) {
150+ return this . player . isMuted ( ) ;
151+ } ,
152+ setVolume ( volume ) {
153+ this . player . setVolume ( volume ) ;
154+ } ,
155+ getVolume ( ) {
156+ return this . player . getVolume ( ) ;
157+ } ,
158+ setSize ( width , height ) {
159+ this . player . setSize ( width , height ) ;
160+ } ,
161+ getPlaybackRate ( ) {
162+ return this . player . getPlaybackRate ( ) ;
163+ } ,
164+ setPlaybackRate ( suggestedRate ) {
165+ this . player . setPlaybackRate ( suggestedRate ) ;
166+ } ,
167+ getAvailablePlaybackRates ( ) {
168+ return this . player . getAvailablePlaybackRates ( ) ;
169+ } ,
170+ setLoop ( loopPlaylists ) {
171+ this . player . setLoop ( loopPlaylists ) ;
172+ } ,
173+ setShuffle ( shufflePlaylist ) {
174+ this . player . setShuffle ( shufflePlaylist ) ;
175+ } ,
176+ getVideoLoadedFraction ( ) {
177+ return this . player . getVideoLoadedFraction ( ) ;
178+ } ,
179+ getPlayerState ( ) {
180+ return this . player . getPlayerState ( ) ;
181+ } ,
182+ getCurrentTime ( ) {
183+ return this . player . getCurrentTime ( ) ;
184+ } ,
185+ getPlaybackQuality ( ) {
186+ return this . player . getPlaybackQuality ( ) ;
187+ } ,
188+ setPlaybackQuality ( suggestedQuality ) {
189+ this . player . setPlaybackQuality ( suggestedQuality ) ;
190+ } ,
191+ getAvailableQualityLevels ( ) {
192+ return this . player . getAvailableQualityLevels ( ) ;
193+ } ,
194+ getDuration ( ) {
195+ return this . player . getDuration ( ) ;
196+ } ,
197+ getVideoUrl ( ) {
198+ return this . player . getVideoUrl ( ) ;
199+ } ,
200+ getVideoEmbedCode ( ) {
201+ return this . player . getVideoEmbedCode ( ) ;
202+ } ,
203+ getPlaylist ( ) {
204+ return this . player . getPlaylist ( ) ;
205+ } ,
206+ getPlaylistIndex ( ) {
207+ return this . player . getPlaylistIndex ( ) ;
208+ } ,
209+ getIframe ( ) {
210+ return this . player . getIframe ( ) ;
211+ } ,
212+ } ,
99213 mounted ( ) {
100214 const { playerHeight, playerWidth, playerParameters, videoId } = this ;
101215 manager . register ( ( factory , uid ) => {
102- const host = this . noCookie
103- ? 'https://www.youtube-nocookie.com'
104- : 'https://www.youtube.com' ;
216+ const host = this . noCookie ? 'https://www.youtube-nocookie.com' : 'https://www.youtube.com' ;
105217 this . elementId = uid ;
106218 vue . nextTick ( ) . then ( ( ) => {
107- this . player = new factory . Player ( this . elementId , {
219+ this . player = createPlayer ( factory , this . elementId , {
108220 width : playerWidth ,
109221 height : playerHeight ,
110222 ...playerParameters ,
111223 videoId,
112224 host,
113225 events : {
114226 onReady : ( event ) => {
115- skipIfAutoplay ( event . target , playerParameters ) ;
227+ seekIfAutoplay ( event . target , playerParameters ) ;
116228 this . $emit ( 'ready' , event ) ;
117229 } ,
118230 onStateChange : ( event ) => {
@@ -128,7 +240,13 @@ const player = {
128240 } ) ;
129241 } ) ;
130242 } ,
131- } ;
243+ unmounted ( ) {
244+ this . player . destroy ( ) ;
245+ } ,
246+ } ) ;
247+ function createPlayer ( factory , id , options ) {
248+ return new factory . Player ( id , options ) ;
249+ }
132250
133251const plugin = {
134252 install : ( app ) => {
0 commit comments