Disable iOS Safari lock screen scrubber for media

后端 未结 3 495
时光取名叫无心
时光取名叫无心 2021-01-18 10:31

Safari on iOS puts a scrubber on its lock screen for simple HTMLAudioElements. For example:

const a = new Audio();
a.src = \'https://example.com/audio.m4a\'         


        
3条回答
  •  甜味超标
    2021-01-18 11:01

    DISABLE Player on lock screen completely

    if you want to completely remove the lock screen player you could do something like

    const a = new Audio();
    document.querySelector('button').addEventListener('click', (e) => {
      a.src = 'http://sprott.physics.wisc.edu/wop/sounds/Bicycle%20Race-Full.m4a' 
      a.play();
    });
    
    document.addEventListener('visibilitychange', () => {
      if (document.hidden) a.src = undefined
    })
    
    

    https://jsfiddle.net/5s8c9eL0/3/

    that is stoping the player when changing tab or locking screen (code to be cleaned improved depending on your needs)

提交回复
热议问题