How do you stop music from playing when reloading the app on the iOS simulator?

#1

Corollary question is if there is any callback or signal when the app is reloaded? componentWillUnmount doesn’t seem to be called

#2

@greg can help you with this one! componentWillUnmount is called, you can verify this by just logging something in your app somewhere in componentWillUnmount

#3

componentWillUnmount is not being called. You can run the following code through XDE client, run through the simulator, and hit reload to reproduce.

import React, { Component } from 'react';
import { View, Text } from 'react-native';
import Expo, { Audio } from 'expo';

export default class App extends Component {
  componentDidMount() {
    this.playMusic();
  }

  componentWillUnmount() {
    this.stopMusic();
  }

  playMusic = async () => {
    const { sound } = await Audio.Sound.create('path_to_audio.mp3', { shouldPlay: true, isLooping: true });
    this.audioPlayer = sound;
  }

  stopMusic = async () => {
    await this.audioPlayer.stopAsync();
  }

  render() {
    return (
      <View>
        <Text>Reload me!</Text>
      </View>
    );
  }
}

Expo.registerRootComponent(App);
#4

is this android or ios?

#5

is this android or ios?

iOS simulator

#6

@kicktheken There was a known bug in SDK 17 where Audio would continue to play after “live reloading” (caused by saving a source file after changing it) the app. We’ve fixed this and the fix is in SDK 18 which should be out this week!

2 Likes
#7

@nikki
Is it possible that we brought this bug back?
I’m still coming across this bug in SDK 27, I have an isolated repro here: https://snack.expo.io/@capitanredbeard/audio-reload-bug

You have to copy that code and plop it in a blank expo project since it only seems to happen on an iOS Simulator. But this bug makes development really annoying.

Let me know if you have trouble reproducing it.
Appreciate any help!

#8

@sjchmiela any idea?

#9

I’m seeing this as well on my app. I can try and provide a snack if needed.

#10

tracking this internally, @sjchmiela is pretty busy but it’s on his queue!

#11

While refactoring native audio code I didn’t take into consideration that Cmd + R works a little bit different than device shake + tap on Reload. I’ll see what I can do about it. :slightly_smiling_face:

#12

Thanks for your patience, I’ve submitted an upstream PR fixing this issue. :slightly_smiling_face: Should be released in the next version of Expo Client.

1 Like