@@ -42,6 +42,7 @@ import { ArtPlayerIconsSubtitle } from "~/components/icons"
4242import { useNavigate } from "@solidjs/router"
4343import "./artplayer.css"
4444import { registerAc3Decoder } from "@mediabunny/ac3"
45+ import { requestTranscodePlay } from "~/utils/media_api"
4546// 仅在启用 MediaBunny 时注册 AC3 解码器
4647if ( isMediaBunnyEnabled ( ) ) {
4748 registerAc3Decoder ( )
@@ -350,17 +351,43 @@ const Preview = () => {
350351 } ,
351352 } )
352353
353- onMount ( ( ) => {
354- // 预下载视频文件的前几个区块(不阻塞,与 Artplayer 初始化同时进行)
355- if ( objStore . raw_url ) {
354+ onMount ( async ( ) => {
355+ // ---- 云端转码判断 ----
356+ // 播放前先调用后端转码决策接口,如果需要转码则使用 HLS master_url 播放
357+ let useTranscode = false
358+ try {
359+ const tcResp = await requestTranscodePlay ( pathname ( ) )
360+ if (
361+ tcResp . code === 200 &&
362+ tcResp . data ?. transcode &&
363+ tcResp . data . master_url
364+ ) {
365+ useTranscode = true
366+ option . url = tcResp . data . master_url
367+ option . type = "m3u8"
368+ console . log (
369+ `[transcode] 使用云端转码播放: job=${ tcResp . data . job_id } , profile=${ tcResp . data . profile } ` ,
370+ )
371+ }
372+ } catch ( e ) {
373+ // 转码接口失败(可能未开启),静默降级到直链播放
374+ console . debug ( "[transcode] 转码接口不可用,使用直链播放" , e )
375+ }
376+
377+ // 预下载视频文件的前几个区块(仅直链模式,转码模式由 HLS.js 管理)
378+ if ( ! useTranscode && objStore . raw_url ) {
356379 void prefetchVideoChunks ( objStore . raw_url , {
357380 byteRange : 8 * 1024 * 1024 ,
358381 timeoutMs : 3000 ,
359382 } )
360383 }
361384 player = new Artplayer ( option )
362- // “仅音频”模式:原生 <video> 解码视频,mediabunny 只提供音轨
363- if ( getMediaBunnyMode ( ) === "audio_only" && objStore . raw_url ) {
385+ // "仅音频"模式:原生 <video> 解码视频,mediabunny 只提供音轨(仅直链模式)
386+ if (
387+ ! useTranscode &&
388+ getMediaBunnyMode ( ) === "audio_only" &&
389+ objStore . raw_url
390+ ) {
364391 attachMediabunnyAudio ( player , objStore . raw_url )
365392 }
366393 let auto_fullscreen : boolean
0 commit comments