Occasional error "{AppName} keeps stopping", on closing an app with react-native-track-player in the foreground

huangapple go评论69阅读模式
英文:

Occasional error "{AppName} keeps stopping", on closing an app with react-native-track-player in the foreground

问题

我正在创建一个应用程序,该应用程序在前台使用react-native-track-player。偶尔在关闭应用程序时,我会收到一个安卓消息App Name keeps stopping
错误反馈提供了以下细节

报告类型:崩溃
包名称:com.myApp
包版本:1004
包版本名称:1.0.0
由com.android.vending安装
进程名称:com.myApp
时间:2023年4月3日星期一
系统应用:false
系统:
设备:a02
构建类型:用户
型号:SM-M022G
产品:a02ins
SDK版本:30
发布:11
代号:REL
崩溃:
异常类名:java.lang.NumberFormatException
源文件:Integer.java
源类:java.lang.Integer
源方法:parseInt
行号:615
堆栈跟踪:
java.lang.numberformatexception: For input string: "null"
在java.lang.Integer.parseInt(Integer.java: 615)
在java.lang.Integer.parseInt(Integer.java: 650)
在com.doublesymmetry.trackplayer.module.MusicModule$q.m(Unknown Source:64)
在g8.a.e(Unknown Source:11)
在w8.u0.run(Unknown Source:129)
在android.os.Handler.handleCallback(Handler.java:938)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:246)
在android.app.Handler.ActivityThread.main(ActivityThread.java:8633)
在java.lang.reflect.Method.invoke(Native Method)
在com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
抑制:w8.s0: [b2{Cancelling}@183e27f, Dispatchers.Main]

我在*./index.js*中注册了TrackPlayer的PlaybackService。

// ./index.js
import {AppRegistry} from 'react-native';
import TrackPlayer from 'react-native-track-player';

import {PlaybackService} from './service';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
TrackPlayer.registerPlaybackService(() => PlaybackService);

TrackPlayer的Playback Services 存储在*./service.js*中。

// ./service.js
import TrackPlayer, {Event} from 'react-native-track-player';

export const PlaybackService = async function () {
  TrackPlayer.addEventListener(Event.RemotePlay, () => TrackPlayer.play());
  TrackPlayer.addEventListener(Event.RemotePause, () => TrackPlayer.pause());
};

这是我如何设置track player的方式。

// ./App.js
  const track = {
    id: 0,
    url: 'https://streaming.test.net:12345/auto-dj',
    title: 'ShoutCast Stream',
    artist: 'React Native',
    genre: 'ShoutCast Stream',
    artwork: 'https://d33l68.cloudfront.net/5540b349/ecfc9/img/header_logo.svg',
  };

  const setUpTrackPlayer = async track => {
    try {
      await TrackPlayer.setupPlayer();
      await TrackPlayer.updateOptions({
        stopWithApp: true,
        android: {
          appKilledPlaybackBehavior:
            AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
        },
        // 媒体控制功能
        capabilities: [Capability.Play, Capability.Pause],

        // 当通知以紧凑形式显示在Android上时会显示的功能
        compactCapabilities: [Capability.Play, Capability.Pause],
      });
      await TrackPlayer.add([track]);
      TrackPlayer.play();
    } catch (err) {
      console.error(`无法设置track player。 ${err}`);
      TrackPlayer.remove();
    }
  };

  useEffect(() => {
    setUpTrackPlayer(track);

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

如何停止错误弹出?

英文:

I am creating an app which uses react-native-track-player in the foreground. Occasionally on closing the app I get an android message App Name keeps stopping.
Occasional error "{AppName} keeps stopping", on closing an app with react-native-track-player in the foreground

The error feedback on the device provides the following details

Report Type: Crash
Package name: com.myApp

Package version: 1004
Package version name: 1.0.0
Installed by: com.android.vending
Process name: com.myApp
Time: Monday, 3 April 2023
System app: false
System: 
  Device: a02
  Build type: user
  Model: SM-M022G
Product: a02ins
SDK version: 30
Release: 11
Codename: REL
Crash:
  Exception class name: java.lang.NumberFormatException
  Source file: Integer.java
  Source class: java.lang.Integer
  Source method: parseInt
  Line number: 615
  Stack trace: 
    java.lang.numberformatexception: For input string: "null" 
    at java.lang.Integer.parseInt(Integer.java: 615) 
    at java.lang.Integer.parseInt(Integer.java: 650) 
    at com.doublesymmetry.trackplayer.module.MusicModule$q.m(Unknown Source:64)
    at g8.a.e(Unknown Source:11)
    at w8.u0.run(Unknown Source:129)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.Handler.ActivityThread.main(ActivityThread.java:8633)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
    Suppressed: w8.s0: [b2{Cancelling}@183e27f, Dispatchers.Main]

I am registering the TrackPlayer's PlaybackService in the ./index.js.

// ./index.js
import {AppRegistry} from 'react-native';
import TrackPlayer from 'react-native-track-player';

import {PlaybackService} from './service';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
TrackPlayer.registerPlaybackService(() => PlaybackService);

And the TrackPlayer's Playback Services are stored in ./service.js

// ./service.js
import TrackPlayer, {Event} from 'react-native-track-player';

export const PlaybackService = async function () {
  TrackPlayer.addEventListener(Event.RemotePlay, () => TrackPlayer.play());
  TrackPlayer.addEventListener(Event.RemotePause, () => TrackPlayer.pause());
};

And this is how I am setting up the track player.

// ./App.js
  const track = {
    id: 0,
    url: 'https://streaming.test.net:12345/auto-dj',
    title: 'ShoutCast Stream',
    artist: 'React Native',
    genre: 'ShoutCast Stream',
    artwork: 'https://d33l68.cloudfront.net/5540b349/ecfc9/img/header_logo.svg',
  };

  const setUpTrackPlayer = async track => {
    try {
      await TrackPlayer.setupPlayer();
      await TrackPlayer.updateOptions({
        stopWithApp: true,
        android: {
          appKilledPlaybackBehavior:
            AppKilledPlaybackBehavior.StopPlaybackAndRemoveNotification,
        },
        // Media controls capabilities
        capabilities: [Capability.Play, Capability.Pause],

        // Capabilities that will show up when the notification is in the compact form on Android
        compactCapabilities: [Capability.Play, Capability.Pause],
      });
      await TrackPlayer.add([track]);
      TrackPlayer.play();
    } catch (err) {
      console.error(`Could not setup track player. ${err}`);
      TrackPlayer.remove();
    }
  };

  useEffect(() => {
    setUpTrackPlayer(track);

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

How can I stop the error from popping up?

答案1

得分: 0

自我回答如下。
问题在于我使用了 react-native-track-player: ˆ3.2.0。将包更新到 版本4.0.0-rc04,使用以下命令修复了这个问题。

npm i react-native-track-player@4.0.0-rc04

有关更多信息,请查看此问题

英文:

Self answer here.
The problem was that I was using react-native-track-player: ˆ3.2.0. Updating the package to Version 4.0.0-rc04 using

npm i react-native-track-player@4.0.0-rc04

fixed the issue.

For more info checkout this issue.

huangapple
  • 本文由 发表于 2023年3月31日 20:15:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75898428.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定