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

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

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

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);

is this android or ios?

is this android or ios?

iOS simulator

@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

@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: Audio Reload Bug - Snack

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!

@sjchmiela any idea?

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

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

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:

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