-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(webview): disable av1 for websites
close #337
- Loading branch information
Showing
15 changed files
with
82 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { around } from "monkey-around"; | ||
|
||
const av1Codec = /codecs="?av01\./; | ||
|
||
export function noAV1() { | ||
const unloads = [ | ||
around(HTMLMediaElement.prototype as HTMLMediaElement, { | ||
canPlayType: (next) => | ||
function canPlayType(this: HTMLVideoElement, type: string) { | ||
if (av1Codec.test(type)) return ""; | ||
return next.call(this, type); | ||
}, | ||
}), | ||
around(window.MediaSource, { | ||
isTypeSupported: (next) => | ||
function isTypeSupported(this: typeof MediaSource, type: string) { | ||
if (av1Codec.test(type)) return false; | ||
return next.call(this, type); | ||
}, | ||
}), | ||
]; | ||
return () => unloads.forEach((u) => u()); | ||
} |
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
apps/app/src/web/bili-req/scripts/preload.ts → apps/app/src/web/preload/scripts/preload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { XHRIntercepter } from "@/lib/remote-player/lib/xhr-hijack"; | ||
import { noAV1 } from "./no-av1"; | ||
import { storeId } from "./store-id"; | ||
|
||
noAV1(); | ||
|
||
if (location.hostname.includes("bilibili.com")) { | ||
const patterns = [ | ||
{ hostname: "api.bilibili.com", pathname: "/x/player/v2" }, | ||
{ hostname: "api.bilibili.com", pathname: "/x/player/wbi/v2" }, | ||
].map((p) => new URLPattern(p)); | ||
|
||
const intercepter = new XHRIntercepter((url) => | ||
patterns.some((p) => p.test(url)), | ||
); | ||
intercepter.load(); | ||
(window as any)[storeId] = intercepter; | ||
|
||
const enum Codec { | ||
default = 0, | ||
hevc = 1, | ||
avc = 2, | ||
av1 = 3, | ||
} | ||
|
||
localStorage.setItem("recommend_auto_play", "close"); | ||
// disable autoplay | ||
localStorage.setItem( | ||
"bpx_player_profile", | ||
JSON.stringify({ media: { autoplay: false } }), | ||
); | ||
// default to hevc | ||
localStorage.setItem( | ||
"bilibili_player_codec_prefer_type", | ||
JSON.stringify(Codec.hevc), | ||
); | ||
|
||
console.log("intercepter loaded"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters