positionMillis of playbackObject does not work on Android devices

SDK Version: 42
Platforms: Android
Library: expo-av

I have a problem with the following mp3 file: https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3

When I load this audio file, using expo-av, as my playbackObject on an Android device and play it (using playAsync()), the positionMillis value suddenly stops at 1 and gets stuck. However, the audio continues running and I can here it. Here you can see a screenshot of how the key-value pairs of the status of the playbackObject change:

This is very strange, as when I test it with an iPhone (iOS 6s), the problem does not occur. There, the positionMillis gets updated with time, as you would expect.

The problem does not occur with other mp3 file URLs I have tried (I have tested on 5 in total). However, I am worried that it might occur again once my app is in production, the app will scrape and play different audio URLs.

Could you please provide some assistance on this issue? Is there a bug in the library?

Thank you in advance.

Hey @vdo, could you please share your actual code implementation for this? As well as what devices/OS versions you have tested on?

Cheers,
Adam

Hey @adamjnav, thanks for your quick reply!

My code is quite long, so I created a new blank project, just by using expo init, and loaded the audio file there. Here are the contents of my App.js:

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Audio } from 'expo-av';
import Icon from '@expo/vector-icons/FontAwesome5'

async function play() {
    const {sound: playbackObject} = await Audio.Sound.createAsync(
        {uri: 'https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3'},
        {shouldPlay: true}
    );
    let status = await playbackObject.getStatusAsync();
    console.log(status);
    let x = 0;
    const interval = setInterval(async () => {
        if (x === 3) {
            clearInterval(interval);
            await playbackObject.unloadAsync();
        } else {
            x += 1
        }
        let status = await playbackObject.getStatusAsync();
        console.log(status);
    }, 3000)
}

export default function App() {
    return (
        <View style={styles.container}>
            <Text>Open up App.js to start working on your app!</Text>
            <Icon name="play" onPress={play}/>
            <StatusBar style="auto"/>
        </View>
    );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

The code is really simple, the audio file will run just for 9 seconds, but that is enough to illustrate the problem.

This code was tested on a physical device with Android 11 and also on an Android Virtual Device API 23. In both cases, positionMillis gets stuck at 1.

The problem does not happen on an iPhone, iOS 6s.

Just let me know in case you need additional infos.

Cheers,
Vladimir

Hey everyone,

just wanted to quickly ask whether there are any updates on this topic (before it closes automatically)?

Cheers,
Vladimir

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.