# What Is The Correct Way To Play A New Song?

**URL:** <https://qa.fmod.com/t/what-is-the-correct-way-to-play-a-new-song/20422>\
**Category:** Unity\
**Created:** [July 14, 2023, 10:44pm UTC](https://qa.fmod.com/t/what-is-the-correct-way-to-play-a-new-song/20422 "2023-07-14T22:44:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![libio1991](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@libio1991](https://qa.fmod.com/u/libio1991)\
**Post date:** [July 14, 2023, 10:44pm UTC](https://qa.fmod.com/t/what-is-the-correct-way-to-play-a-new-song/20422/1 "2023-07-14T22:44:21Z")

</div>

Good Evening All,

I created a method that stops playing the current song and then plays a new song. Though, I’m not certain if this is the best way to do it:

```auto
public void PlaySong(EventReference song)
    {
        // If a previous song is playing stop it.
        currentSong.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);

        // Set the current song
        currentSong = RuntimeManager.CreateInstance(song);

        // Play the new song
        currentSong.start();
        
    }

```

Rather than always trying to stop a song, I wanted to do a check to see if currentSong is either null or currently playing. Though it looks like using if (currentSong != null) is not valid.

Is there a better way to first check if a song is playing, stop it if so, and then finally play a new song?

Thanks so much for taking the time! 😊

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 17, 2023, 10:27pm UTC](https://qa.fmod.com/t/what-is-the-correct-way-to-play-a-new-song/20422/2 "2023-07-17T22:27:16Z")

</div>

Hi,

To check if FMOD variables are valid you can use `currentSong.isValid()` and to check if an instance is currently playing you can check its `Playback State` ([FMOD Engine | Studio API Reference - Common](https://fmod.com/docs/2.02/api/studio-api-common.html#fmod_studio_playback_state))

```auto
currentSong.getPlaybackState(out FMOD.Studio.PLAYBACK_STATE playbackState);

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![libio1991](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@libio1991](https://qa.fmod.com/u/libio1991)\
**Post date:** [July 18, 2023, 9:24pm UTC](https://qa.fmod.com/t/what-is-the-correct-way-to-play-a-new-song/20422/3 "2023-07-18T21:24:00Z")

</div>

Thank you very much for the response!

Just to clarify, isValid() returns false if its null and true if a song(EventReferenceAsset) is already playing, correct?

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 19, 2023, 2:41am UTC](https://qa.fmod.com/t/what-is-the-correct-way-to-play-a-new-song/20422/4 "2023-07-19T02:41:43Z")

</div>

Hi,

Apologies I missed linking the `isValid()` documentation here: [FMOD Engine | Studio API Reference - Event Instance](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#studio_eventinstance_isvalid).  
In summary, it will check the `event instance` has been instantiated not its current `playback state`. To check its current state use `currentSong.getPlaybackState()`

Hope this helps
