You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FireTV Stick休眠模式视频后台播放致React Native TV应用亚马逊验证失败

解决FireTV休眠返回后音频持续播放的问题

针对你提交亚马逊应用商店时遇到的FireTV-24-Media错误,结合你使用的react-native-tvos@0.69.8-1和react-native-video@5.2.1版本,提供以下修复方案:

1. 监听AppState状态手动控制播放暂停

虽然你已经设置了playInBackground={false}和playWhenInactive={false},但FireTV休眠场景下可能未触发组件自动暂停逻辑,需要通过AppState监听主动控制:

import { AppState } from 'react-native';

// 在组件中添加状态监听
useEffect(() => {
  const handleAppStateChange = (nextAppState) => {
    // 应用进入后台/inactive状态时强制暂停播放
    if (nextAppState === 'background' || nextAppState === 'inactive') {
      if (playerRef.current) {
        playerRef.current.pause();
        pausedRef.current = true;
      }
    }
    // 可选:唤醒后按需恢复播放(根据业务需求调整)
    // if (nextAppState === 'active') {
    //   if (playerRef.current && needResumePlayback) {
    //     playerRef.current.play();
    //     pausedRef.current = false;
    //   }
    // }
  };

  const subscription = AppState.addEventListener('change', handleAppStateChange);

  return () => subscription.remove();
}, []);

确保playerRef正确关联Video组件:

const playerRef = useRef(null);

<Video
  ref={playerRef}
  // 其他原有属性保持不变
/>

2. 监听FireTV系统休眠广播(Android原生补充)

FireTV休眠时会发送系统广播,可通过原生模块监听并通知RN层暂停播放:

Android原生代码(MainActivity.java)

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.modules.core.DeviceEventManagerModule;

public class SleepReceiverModule extends ReactContextBaseJavaModule {
    private BroadcastReceiver sleepReceiver;

    public SleepReceiverModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "SleepReceiver";
    }

    @ReactMethod
    public void registerSleepListener() {
        sleepReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
                    // 发送休眠事件到RN层
                    getReactApplicationContext()
                        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                        .emit("onDeviceSleep", null);
                }
            }
        };

        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        getReactApplicationContext().registerReceiver(sleepReceiver, filter);
    }

    @ReactMethod
    public void unregisterSleepListener() {
        if (sleepReceiver != null) {
            getReactApplicationContext().unregisterReceiver(sleepReceiver);
        }
    }
}

RN层监听事件:

import { NativeEventEmitter, NativeModules } from 'react-native';

const { SleepReceiver } = NativeModules;
const sleepEmitter = new NativeEventEmitter(SleepReceiver);

useEffect(() => {
  SleepReceiver.registerSleepListener();
  const subscription = sleepEmitter.addListener('onDeviceSleep', () => {
    if (playerRef.current) {
      playerRef.current.pause();
      pausedRef.current = true;
    }
  });

  return () => {
    SleepReceiver.unregisterSleepListener();
    subscription.remove();
  };
}, []);

3. 验证版本兼容性与属性生效

检查react-native-video@5.2.1在tvos环境下的playInBackground/playWhenInactive属性是否存在适配问题,若有条件可尝试升级到该库的最新稳定tvos兼容版本。

4. 测试验证

修复后严格按照亚马逊复现步骤测试:

  • 启动应用播放视频
  • 触发休眠后唤醒设备
  • 确认音频停止,应用状态符合预期

内容的提问来源于stack exchange,提问作者vishal dodiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 11:52:16