react-native-track-player: Crash on Android

Describe the bug My android app is crashing but it is working fine on IOS. it crashes 1 time in every 3 -4 attempts not every time -

Exception in native call- java.lang.NullPointerException: Attempt to invoke virtual method ‘boolean android.os.Handler.post(java.lang.Runnable)’ on a null object reference

Image ->> https://lh3.googleusercontent.com/-xaRP4BB5EHk/YM-PoYdmWLI/AAAAAAAABvg/t0LIUg2bcsEl8KC4IfRjNqIkBY077OjAQCJEEGAsYHg/s0/2021-06-20.jpg?authuser=0

To Reproduce Steps to reproduce the behavior:

Environment (please complete the following information): Run react-native info in your project and share the content.

System: OS: Windows 10 10.0.19041 CPU: (8) x64 Intel® Core™ i5-1035G1 CPU @ 1.00GHz Memory: 490.54 MB / 7.78 GB Binaries: Node: 12.18.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.4 - ~\AppData\Roaming\npm\yarn.CMD npm: 6.14.5 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 27, 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.1, 30.0.2 System Images: android-22 | Intel x86 Atom_64, android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom Android NDK: 22.1.7171670 Windows SDK: Not Found IDEs: Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7322048 Visual Studio: Not Found Languages: Java: 1.8.0_211 Python: 3.8.3 npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

What react-native-track-player version are you using? “react-native-track-player”: “^1.2.7”,

Are you testing on a real device or in the simulator? Which OS version are you running?

On real device

Code Please, share the code that is causing the issue

const setupPlayer = async () => {
    await TrackPlayer.setupPlayer();
    await TrackPlayer.updateOptions({
        stopWithApp: true,
        capabilities: [
            TrackPlayer.CAPABILITY_PLAY,
            TrackPlayer.CAPABILITY_PAUSE,
            TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
            TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
            TrackPlayer.CAPABILITY_STOP,
        ],
        compactCapabilities: [
            TrackPlayer.CAPABILITY_PLAY,
            TrackPlayer.CAPABILITY_PAUSE,
        ],
        notificationCapabilities: [
            TrackPlayer.CAPABILITY_PLAY,
            TrackPlayer.CAPABILITY_PAUSE,
            TrackPlayer.CAPABILITY_SKIP_TO_NEXT,
            TrackPlayer.CAPABILITY_SKIP_TO_PREVIOUS,
            TrackPlayer.CAPABILITY_STOP,
        ],
    });
};

//***** For Generating playlist of audios

export const generatePlaylistFromTimeline = (startIndex) => {
    return async (dispatch, getState) => {
        await setupPlayer();
        const timelineState = getState().timeline.timeline;
        let newsList = [...timelineState.feed];
        const startIndexId = newsList[startIndex] ? newsList[startIndex].id : 0 ;
        console.log("!!!!",startIndexId);
        newsList = newsList.filter(item => item.type === 'news');
        newsList = newsList.map(item => item.id);

        const userState = getState().user;
        const newsInterests = userState.newsInterests || [];
        const identifier = newsInterests.join(',');

        let lastId = newsList[newsList.length - 1];
        let lastTime = getState().news.byIds[lastId].createdAt;
        console.log('Generating LastTime: ', lastTime);
        lastTime = new Date(lastTime).getTime();
        console.log('Generating LastTime: ', lastTime);
        console.log(newsList);
        const newStartIndex = newsList.indexOf(startIndexId);
        console.log(newStartIndex);
        const payload = {
            tracks: newsList,
            currentTrack: newsList[newStartIndex],
            identifier: identifier,
            lastTime: lastTime,
            paging: timelineState.paging,
        };
        dispatch(savePlaylist(payload));
        await setTracks(newsList, newStartIndex, getState);
    };
};

// *** Start playing the selected track

const setTracks = async (trackList, startIndex, getState) => {
    const newsByIds = getState().news.byIds;
    await TrackPlayer.reset();
    const tracks = trackList.map(track => {
        const newsItem = newsByIds[track];
        return {
            id: track,
            url: newsItem.audioUrl,
            title: newsItem.headline,
            artist: newsItem.categories[0],
            artwork: newsItem.images[0],
        };
    });
    await TrackPlayer.add(tracks);
    await TrackPlayer.skip(trackList[startIndex]);
    await TrackPlayer.play();
};

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 24 (4 by maintainers)

Most upvoted comments

Hey @dcvz, we tried installing the beta on Podverse but we are getting the following Kotlin error on built time:

A problem occurred evaluating project ':react-native-track-player'.
> Plugin with id 'kotlin-android' not found.

I think there is something like an import missing in your node_module export. Not sure what it is because I’ve not dabbled with Kotlin too much.

cc @mitchdowney

@kreonjr this particular issue is resolved in v2.2.0-rc3 via https://github.com/doublesymmetry/react-native-track-player/pull/1446.

This should be fixed in #1371

Can y’all help us test this out and see?

@mrigo @kreonjr @mattiaefesto @nickmcmillan @mohity777

v3.1 is now out. If you’re having issues with Android 12 please upgrade to the latest version.

Thanks for the updates here, are any of you able to try our current pre release of the Android rewrite? We believe we’ve sorted out a whole class of crashes there, but would love some feedback.