@@ -54,7 +54,7 @@ export class Controller {
5454
5555 public constructor ( context : AppContext < Attributes > ) {
5656 this . context = context ;
57- const { src, provider, type, paused , poster } = this . context . storage . state ;
57+ const { src, provider, type, poster } = this . context . storage . state ;
5858 const _type = provider ? undefined : type || guessTypeFromSrc ( src ) ;
5959 this . playerContainer = this . createPlayerContainer ( { src, poster, provider, type : _type } ) ;
6060 ( window as any ) . plyrController = this ;
@@ -143,9 +143,14 @@ export class Controller {
143143 get duration ( ) : number {
144144 return this . player ?. duration || 0 ;
145145 }
146-
147146 private hasPermission = ( _operation : PlayerOperationType ) :PermissionType => {
148147 // todo 如果客户需要更细粒度的权限控制,可以在这里添加
148+ if ( _operation === 'volume' && ! this . context . storage . state . syncVolume ) {
149+ return 'local' ;
150+ }
151+ if ( _operation === 'muted' && ! this . context . storage . state . syncMuted ) {
152+ return 'local' ;
153+ }
149154 if ( this . context . getIsWritable ( ) ) {
150155 return 'sync' ;
151156 }
@@ -165,10 +170,10 @@ export class Controller {
165170 muted ?: boolean ;
166171 playTimeState ?: PlayTimeState ;
167172 } = { } ;
168- if ( this . player . volume !== this . volumeData ) {
173+ if ( this . player . volume !== this . volumeData && this . context . storage . state . syncVolume ) {
169174 willUpdateAttr . volume = this . volumeData ;
170175 }
171- if ( this . player . muted !== this . mutedData ) {
176+ if ( this . player . muted !== this . mutedData && this . context . storage . state . syncMuted ) {
172177 willUpdateAttr . muted = this . mutedData ;
173178 }
174179 const playTimeState = this . playTimeState ;
@@ -269,7 +274,6 @@ export class Controller {
269274 try {
270275 loop ++ ;
271276 await this . player . play ( ) ;
272- // this.checkPlayMuted();
273277 } catch ( error ) {
274278 console . error ( '[app plyr] play error' , error ) ;
275279 if ( this . player ) {
@@ -280,57 +284,6 @@ export class Controller {
280284 }
281285 }
282286
283- // private checkPlayMuted = () => {
284- // setTimeout(async () => {
285- // if (!this.player) {
286- // return;
287- // }
288- // if (this.player.muted !== this.mutedData) {
289- // const mutedDom = this.player.elements.container?.querySelector('.plyr__volume button') as HTMLButtonElement;
290- // // mutedDom.click();
291- // // try {
292- // // const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false })
293- // // console.log("设备权限已获取,自动播放限制可能已解除");
294- // // stream.getTracks().forEach(track => track.stop());
295- // // } catch (error) {
296- // // console.log("权限请求失败", error);
297- // // }
298- // // 在页面初始化时,尝试请求用户媒体权限
299-
300- // // .then(function(stream) {
301- // // // 权限获取成功!此时浏览器的自动播放策略可能会放宽
302- // // console.log("设备权限已获取,自动播放限制可能已解除");
303-
304- // // // 注意:这里我们并不真正使用这个stream,目的是获取权限
305- // // // 关闭获取到的媒体轨道
306- // // stream.getTracks().forEach(track => track.stop());
307-
308- // // // 现在尝试播放你的背景音乐
309- // // const audio = new Audio('your-audio.mp3');
310- // // audio.play().catch(e => console.error("最终还是失败了:", e));
311- // // })
312- // // .catch(function(err) {
313- // // // 用户拒绝了权限请求或发生错误,自动播放依然会被阻止
314- // // console.log("权限请求失败", err);
315- // // // 此时需要降级到方案一,引导用户交互
316- // // });
317-
318- // // mutedDom.addEventListener('pointerdown', (e)=>{
319- // // console.log('[app plyr] checkPlayMuted pointerdown===>', e);
320- // // });
321- // // mutedDom.click();
322- // // 模拟一个pointerdown事件
323- // // const pointerdownEvent = new PointerEvent('pointerdown', {
324- // // bubbles: true,
325- // // cancelable: true,
326- // // composed: true,
327- // // });
328- // // console.log('[app plyr] checkPlayMuted====>', mutedDom, pointerdownEvent);
329- // // mutedDom.dispatchEvent(pointerdownEvent);
330- // }
331- // }, 1000);
332- // }
333-
334287 private createYoutubeContainer ( src : string , poster ?: string ) : HTMLDivElement {
335288 const container = document . createElement ( 'div' ) ;
336289 container . classList . add ( 'plyr__video-embed' ) ;
0 commit comments