globalSpeed icon indicating copy to clipboard operation
globalSpeed copied to clipboard

当页面有多个视频/音频的时候, 进行切换之后需要重新进行音量调整

Open draymondgewade opened this issue 2 years ago • 15 comments

例如ins的快拍的界面, 进行音量调整后, 如20%, 切换之后, 音量会回到100%

同时有一个小问题: ListenNotes的音频界面, 进行音量调整后, 快进或后退, 音量调整会失效, 回到100%

draymondgewade avatar Jun 17 '22 06:06 draymondgewade

Hello. I will look into a memory function for the next major release. For now, you can try this code I wrote for for issue #196. It will save your volume changes you make from Global Speed (or website's own controls), and apply them at the start of the video/audio. It also blocks the website from changing volume in the first 3 seconds. This should block their own memory function from interfering.

Setup (video walkthrough linked below)

  1. Create a URL rule in the options page.
  2. Change it from "speed" mode to "javascript" mode. Click "edit" and paste the code from below.
  3. Click on "-- 0 --" to add a URL condition so that if the URL contains "listennotes.com", it should run the code.
  4. Enable "ILO" so the code only loads once.

[ DELETED ]

https://user-images.githubusercontent.com/31208859/165215878-b9e3b363-7886-4f4d-a1e8-659478cc3338.mov

polywock avatar Jun 17 '22 08:06 polywock

音量记忆的功能太棒了, 但是似乎对于https://www.sportlive.cc/play/20220617/14620.html网页上的这种类型的播放器不生效, 通过这种类似拖动条但是间断的音量 image

draymondgewade avatar Jun 17 '22 09:06 draymondgewade

Deleted previous few comments because incorrect code.

All videos on that website says "Service stopped" for me so I can't reproduce the issue. I think it's because it's a live video, which may trigger the "loadedmetadata" regularly. Let me know if this version works.

if (!window.ranScriptFlag) {
    window.ranScriptFlag = true
    let blockTimeout 
    // block website from changing volume for first 3 seconds. 
    let BLOCK_DURATION = 3000 

    // add event listener to store latest volume. 
    window.addEventListener("volumechange", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 

        localStorage.setItem("gs-volume", video.volume)
    }, true)


    // function to get stored volume 
    const getStoredVolume = () => {
        let volumeRaw = localStorage.getItem("gs-volume")
        if (volumeRaw) {
            return parseFloat(volumeRaw)
        }
    }

    // block page from changing volume 
    const desc = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume")
    Object.defineProperty(HTMLMediaElement.prototype, "volume", {configurable: true, enumerable: true, get: desc.get, set: function(value) {
     return blockTimeout ? undefined : desc.set.call(this, value) 
}})

    // on start of video, set volume to the stored one. 
    window.addEventListener("loadstart", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 
        clearTimeout(blockTimeout)
        blockTimeout = setTimeout(() => { blockTimeout = null }, BLOCK_DURATION)
        desc.set.call(video, getStoredVolume() ?? 0.5)
    }, true)
}

polywock avatar Jun 17 '22 12:06 polywock

非常遗憾, 并没有生效, 可能因为服务地区的问题, 所以导致网站无法访问, 该网站使用的应该是clappr, 以下是它的github地址 https://github.com/clappr/clappr, 它的调节音量的方式是不同的, 调节音量的方式是离散的, 通过判断点击的位置选择填满来调节音量, 所以是阶段式的, 不知道这是否会有影响,如图所示 image

此外, 在使用dplayer的网页中, 只有原播放器音量是100%的时候, 是可以生效的, 不然的话, Global Speed 音量记忆就失效了, (可能是因为dplayer的记住音量的功能的设计似乎是在不是默认值一般是100%的时候会记住, 因此GS才可以在默认100%时生效, 不是默认时则与dplayer冲突), 这可能是一个无伤大雅的问题

draymondgewade avatar Jun 17 '22 12:06 draymondgewade

我觉得可能的最大的问题可能还是与播放器的自带的默认音量的冲突问题

draymondgewade avatar Jun 17 '22 12:06 draymondgewade

I tried testing with the clappr demo but it seems to work fine. It might be that sportlive.cc is resetting volume during particular events (maybe play/pause). The previous code allows the website to change volume after 3 seconds of the video loading. This way you can change volume using website's own controls. This new version doesn't let the website change volume at all. You can only change volume through Global Speed. You can make it so the old code runs on ListenNotes and the new one runs on sportlive.cc. This might fix the issue.

if (!window.ranScriptFlag) {
    window.ranScriptFlag = true

    // add event listener to store latest volume. 
    window.addEventListener("volumechange", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 

        localStorage.setItem("gs-volume", video.volume)
    }, true)


    // function to get stored volume 
    const getStoredVolume = () => {
        let volumeRaw = localStorage.getItem("gs-volume")
        if (volumeRaw) {
            return parseFloat(volumeRaw)
        }
    }

    // block page from changing volume 
    const desc = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume")
    Object.defineProperty(HTMLMediaElement.prototype, "volume", {configurable: true, enumerable: true, get: desc.get, set: function(value) {
     return undefined 
}})

    // on start of video, set volume to the stored one. 
    window.addEventListener("loadstart", e => {
        const video = e.target
        if (!(video instanceof HTMLMediaElement)) return 
        desc.set.call(video, getStoredVolume() ?? 0.5)
    }, true)
}

polywock avatar Jun 17 '22 13:06 polywock

我这还是不可以, 也许是因为该媒体是在网站其他元素已经加载过后再点击播放后再加载的, 您可以试试这个网址时候可以访问, GS是否生效 http://goaltime.tv/tennis-live-3a/, 非常感谢

draymondgewade avatar Jun 17 '22 13:06 draymondgewade

Hello. Using goaltime, I figured out the problem. The video is running inside an iFrame. The script only runs on the top frame. To fix this issue. Remove the scripts from Global Speed and install this userscript version I just published.

https://greasyfork.org/en/scripts/446626-per-domain-volume-memory

After installing, make sure "Run only on top frame" is set to "No".

img2

It will run on all sites by default. You can change that in the settings.

Edit - Just noticed another issue. If you installed already, might need to upgrade to version 1.1

polywock avatar Jun 17 '22 14:06 polywock

  1. 非常感谢, 在脚本更新到1.1之后, 之前的音量记忆存在的问题几乎都解决了, 提一个小建议, 能否将记忆的音量通过某种方法可以显示, 在脚本的注册条目或者网页或者快捷键的某种方式, 不然的话只能通过调节音量的方式来显示

  2. 此外, 非常抱歉, ListenNotes的问题为我调整音量如10%后, 调整时间轴, 无论是使用GS的快捷键, 还是网站默认的, 如图, 都会导致音量重新变为100%, 当我点击进度条, 因为我使用的ArrowDown, ArrownUP调节音量, 这两个快捷键会被进度条占用 image

draymondgewade avatar Jun 18 '22 04:06 draymondgewade

Hello. It's no bother at all. I want to figure out problems with a volume memory feature before I decide to implement it for Global Speed.

(2) is caused by ListenNotes resetting the speed back to it's internal volume. You can upgrade to 1.2 to fix it. It includes a list of domains that are prohibited from changing volume at all.

I included www.listennotes.com already, but you can always edit the list to include more domains.

polywock avatar Jun 18 '22 08:06 polywock

非常感谢, 不知道作者能否访问v.qq.com, 腾讯视频似乎有两种播放器, 新版的脚本会导致刚开始播放的时候声音为0%, 旧版的似乎不能够记忆音量 新版页面: https://v.qq.com/x/cover/mzc00200p51jpn7/t0042h23a9d.html?n_version=2021 旧版页面: https://v.qq.com/x/cover/14vy4qy3j56svv6/v0027h5uimq.html

draymondgewade avatar Jun 18 '22 08:06 draymondgewade

Hello. The new Tencent video player uses CANVAS to play videos. Canvas is a drawing API and is typically used for web games, but some websites are starting to use it to play videos. I tested on the new and old, I don't notice any issue with volume starting at 0%. Not sure what's happening. Does disabling the userscript fix the issue?

polywock avatar Jun 18 '22 14:06 polywock

Yes, disabling the userscript fixs the issue.

draymondgewade avatar Jun 18 '22 14:06 draymondgewade

I've been trying to reproduce your issue with the new player, but with no luck. I noticed the old Tecent player also doesn't work well with the userscript. "qq.com" needs to be added to the block list. Maybe try adding "qq.com" to the block list.

polywock avatar Jun 18 '22 23:06 polywock

我关闭了Chrome的其他插件和脚本, 依旧不能解决这个问题, 将qq.com加入block list后, 打开腾讯视频的音量总是默认为100%, 我在Edge中进行使用, 声音可以播放, 但是用音量调节可以发现, GS的音量依旧为0%, 但网页正常播放声音

draymondgewade avatar Jun 19 '22 01:06 draymondgewade