# Can't stop the channel

**URL:** https://qa.fmod.com/t/cant-stop-the-channel/19901
**Category:** FMOD Engine
**Created:** [February 21, 2023, 9:23pm UTC](https://qa.fmod.com/t/cant-stop-the-channel/19901 "2023-02-21T21:23:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rohit.punjabi](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@rohit.punjabi](https://qa.fmod.com/u/rohit.punjabi)
#### Post date: [February 21, 2023, 9:23pm UTC](https://qa.fmod.com/t/cant-stop-the-channel/19901/1 "2023-02-21T21:23:51Z")

</div>

Hello,

I have 4 channels and all of them are part of 1 Sound\_Effects channel group. If I try to stop only one channel it does not stop.

Thank You

---

<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: [February 22, 2023, 12:14am UTC](https://qa.fmod.com/t/cant-stop-the-channel/19901/2 "2023-02-22T00:14:35Z")

</div>

Hi,

What version of FMOD are you using?

Could you share the code you are using when trying to stop the channel?

---

<div class="post-metadata">

### Author: ![rohit.punjabi](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@rohit.punjabi](https://qa.fmod.com/u/rohit.punjabi)
#### Post date: [February 22, 2023, 11:48pm UTC](https://qa.fmod.com/t/cant-stop-the-channel/19901/3 "2023-02-22T23:48:04Z")

</div>

Hey,

I’m using FMOD version 2.02.08.

Below I have added the code I use to stop

// Creating channels  
FMOD::Channel\* impact\_channel, \* rev\_channel, \* idle\_channel, \* skid\_channel;

// Creating Channel Group  
FMOD::ChannelGroup\* sfx\_chanel\_group;  
fmod\_system-\>createChannelGroup(“sfx\_chanel”, &sfx\_chanel\_group);  
sfx\_chanel\_group-\>setMode(FMOD\_CREATECOMPRESSEDSAMPLE | FMOD\_LOOP\_OFF);

// Setting the group for the channels  
impact\_channel-\>setChannelGroup(sfx\_chanel\_group);  
idle\_channel-\>setChannelGroup(sfx\_chanel\_group);  
rev\_channel-\>setChannelGroup(sfx\_chanel\_group);  
skid\_channel-\>setChannelGroup(sfx\_chanel\_group);

// To play sound  
fmod\_system-\>playSound(loaded\_audio\_files\_map[tag], nullptr, false, &skid\_channell);

// Calling stop at a specific action  
skid\_channel-\>stop();

The system loads the correct sound and plays it but the stop call does not stop the sound it keeps going until the sound file is finished.

---

<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: [February 23, 2023, 2:39am UTC](https://qa.fmod.com/t/cant-stop-the-channel/19901/4 "2023-02-23T02:39:09Z")

</div>

Thanks for sharing that.

I would recommend using `FMOD_RESULT` which is very useful for debugging FMOD function calls. A list of the error codes can be found under [FMOD API | Core API Reference](https://fmod.com/docs/2.02/api/core-api-common.html#fmod_result).

I added your code to the FMOD Examples Found in `C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\examples\vs2019`.

I am not sure if you did not add it but `FMOD::Channels` should be initialized with `= 0` to make sure they are valid memory. This is something that was causing issues for me.

```auto
// Creating channels
FMOD::Channel* impact_channel, * rev_channel, * idle_channel, * skid_channel = 0;

```

> [@rohit.punjabi](#):
>
> // Setting the group for the channels  
> impact\_channel-\>setChannelGroup(sfx\_chanel\_group);  
> idle\_channel-\>setChannelGroup(sfx\_chanel\_group);  
> rev\_channel-\>setChannelGroup(sfx\_chanel\_group);  
> skid\_channel-\>setChannelGroup(sfx\_chanel\_group);
> 
> // To play sound  
> fmod\_system-\>playSound(loaded\_audio\_files\_map[tag], nullptr, false, &skid\_channell);

Here you are trying to call into each of the `Channels` before they have been created by the FMOD System. If you checked the result it would be `An invalid object handle was used.` So to fix this, wait till the sound has been played on the channel and it has been created to assign it to the `ChannelGroup`.

> **Edited FMOD Explame**
>
> ```auto
> #include "fmod.hpp"
> #include "common.h"
> 
> int FMOD_Main()
> {
> FMOD::System* system;
> FMOD::Sound* sound1, * sound2, * sound3;
> FMOD::Channel* channel = 0;
> FMOD_RESULT result;
> void* extradriverdata = 0;
> 
> Common_Init(&extradriverdata);
> 
> /*
> Create a System object and initialize
> */
> result = FMOD::System_Create(&system);
> ERRCHECK(result);
> 
> result = system->init(32, FMOD_INIT_NORMAL, extradriverdata);
> ERRCHECK(result);
> 
> result = system->createSound(Common_MediaPath("drumloop.wav"), FMOD_DEFAULT, 0, &sound1);
> ERRCHECK(result);
> 
> //result = sound1->setMode(FMOD_LOOP_OFF); /* drumloop.wav has embedded loop points which automatically makes looping turn on, */
> //ERRCHECK(result); /* so turn it off here. We could have also just put FMOD_LOOP_OFF in the above CreateSound call. */
> 
> result = system->createSound(Common_MediaPath("jaguar.wav"), FMOD_DEFAULT, 0, &sound2);
> ERRCHECK(result);
> 
> result = system->createSound(Common_MediaPath("swish.wav"), FMOD_DEFAULT, 0, &sound3);
> ERRCHECK(result);
> 
> // Creating channels
> FMOD::Channel* impact_channel, * rev_channel, * idle_channel, * skid_channel = 0;
> 
> // Creating Channel Group
> FMOD::ChannelGroup* sfx_chanel_group;
> result = system->createChannelGroup("sfx_chanel", &sfx_chanel_group);
> ERRCHECK(result);
> 
> result = sfx_chanel_group->setMode(FMOD_CREATECOMPRESSEDSAMPLE | FMOD_LOOP_OFF);
> ERRCHECK(result);
>     
> // Play the sound first 
> result = system->playSound(sound1, nullptr, false, &skid_channel);
> ERRCHECK(result);
> 
> // Once the channel has been created by the FMOD system then add it to the group
> result = skid_channel->setChannelGroup(sfx_chanel_group);
> ERRCHECK(result);
> 
> /*
> Main loop
> */
> do
> {
> Common_Update();
> 
> if (Common_BtnPress(BTN_ACTION1))
> {
> //result = system->playSound(sound1, 0, false, &channel);
> result = skid_channel->stop();
> ERRCHECK(result);
> }
> 
> if (Common_BtnPress(BTN_ACTION2))
> {
> result = system->playSound(sound2, 0, false, &channel);
> ERRCHECK(result);
> }
> 
> if (Common_BtnPress(BTN_ACTION3))
> {
> result = system->playSound(sound3, 0, false, &channel);
> ERRCHECK(result);
> }
> 
> result = system->update();
> ERRCHECK(result);
> 
> {
> unsigned int ms = 0;
> unsigned int lenms = 0;
> bool playing = 0;
> bool paused = 0;
> int channelsplaying = 0;
> 
> if (channel)
> {
> FMOD::Sound* currentsound = 0;
> 
> result = channel->isPlaying(&playing);
> if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
> {
> ERRCHECK(result);
> }
> 
> result = channel->getPaused(&paused);
> if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
> {
> ERRCHECK(result);
> }
> 
> result = channel->getPosition(&ms, FMOD_TIMEUNIT_MS);
> if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
> {
> ERRCHECK(result);
> }
> 
> channel->getCurrentSound(&currentsound);
> if (currentsound)
> {
> result = currentsound->getLength(&lenms, FMOD_TIMEUNIT_MS);
> if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
> {
> ERRCHECK(result);
> }
> }
> }
> 
> system->getChannelsPlaying(&channelsplaying, NULL);
> 
> Common_Draw("==================================================");
> Common_Draw("Play Sound Example.");
> Common_Draw("Copyright (c) Firelight Technologies 2004-2023.");
> Common_Draw("==================================================");
> Common_Draw("");
> Common_Draw("Press %s to play a mono sound (drumloop)", Common_BtnStr(BTN_ACTION1));
> Common_Draw("Press %s to play a mono sound (jaguar)", Common_BtnStr(BTN_ACTION2));
> Common_Draw("Press %s to play a stereo sound (swish)", Common_BtnStr(BTN_ACTION3));
> Common_Draw("Press %s to quit", Common_BtnStr(BTN_QUIT));
> Common_Draw("");
> Common_Draw("Time %02d:%02d:%02d/%02d:%02d:%02d : %s", ms / 1000 / 60, ms / 1000 % 60, ms / 10 % 100, lenms / 1000 / 60, lenms / 1000 % 60, lenms / 10 % 100, paused ? "Paused " : playing ? "Playing" : "Stopped");
> Common_Draw("Channels Playing %d", channelsplaying);
> }
> 
> Common_Sleep(50);
> } while (!Common_BtnPress(BTN_QUIT));
> 
> /*
> Shut down
> */
> result = sound1->release();
> ERRCHECK(result);
> result = sound2->release();
> ERRCHECK(result);
> result = sound3->release();
> ERRCHECK(result);
> result = system->close();
> ERRCHECK(result);
> result = system->release();
> ERRCHECK(result);
> 
> Common_Close();
> 
> return 0;
> }
> 
> ```

Hope this helps!

---

<div class="post-metadata">

### Author: ![rohit.punjabi](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@rohit.punjabi](https://qa.fmod.com/u/rohit.punjabi)
#### Post date: [February 24, 2023, 1:54am UTC](https://qa.fmod.com/t/cant-stop-the-channel/19901/5 "2023-02-24T01:54:21Z")

</div>

Thank you for the help. I’ll try these things out
