Pausing streaming internet radio (UE4.25, FMOD 2.01.07)

,

Hi,

It’s partially referring to what was discussed here Streaming internet radio (UE4) - #15 by DracoNared , but I decided to make a different topic.

It’s not an issue, rather a question for cleanliness of the code for pausing an internet stream.

I was trying different methods to pause the radio and the only one that was not causing any errors is this:

void AFMODRadio::ToggleRadio()
{
    if (isPlaying)
    {
        this->AudioComp->Stop();
        this->Sound->release();
    }
    else
    {
        FMOD_RESULT Result;

        SoundInfo = { 0 };

        SoundInfo.cbsize = sizeof(SoundInfo);
        SoundInfo.ignoresetfilesystem = true;
        SoundInfo.suggestedsoundtype = FMOD_SOUND_TYPE_MPEG;
        SoundInfo.filebuffersize = 1024 * 16;

        Result = CoreSystem->createStream("http://live-radio01.mediahubaustralia.com/2TJW/mp3/",
            FMOD_CREATESTREAM | FMOD_NONBLOCKING,
            &this->SoundInfo,
            &this->Sound);
        if (Result != FMOD_OK)
        {
            UE_LOG(LogTemp, Warning, TEXT("Couldn't create Stream, error: %i"), Result);
            return;
        }

        this->AudioComp->SetProgrammerSound(Sound);
        this->AudioComp->Play();
    }

    isPlaying = !isPlaying;
}

Is it ok to do it this way? I think the best would be to just use

this->AudioComp->SetPaused(isPlaying ? true : false);

but it didn’t work (it did stop the stream, but didn’t restart the stream).

///////
And to remind you, my class looks like this:

class TEST425_API AFMODRadio : public AActor
{
    GENERATED_BODY()
public:
    UFUNCTION(BlueprintCallable)
        void ToggleRadio();

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UFMODAudioComponent* AudioComp;

protected:
    virtual void BeginPlay() override;
// Here I close and release the CoreSystem.
    virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;

    FMOD::System* CoreSystem = nullptr;
    FMOD::Sound* Sound = nullptr;
    FMOD_CREATESOUNDEXINFO SoundInfo = { 0 };

    bool isPlaying = true;
};

There is a ‘netstream’ example included in the API download, which you can use as a bit of a guide.

What sort of errors are you getting when you try to pause/resume the stream?

Yeah, I know; I was trying to get it done like in netstream example, like in the lines:

bool paused = false;
result = channel->getPaused(&paused);
ERRCHECK(result);
result = channel->setPaused(!paused);
ERRCHECK(result);

But the main problem is that in UE4 a channel is not needed to create or play a stream and thus it is not assigned.

Any way I can see of to get a channel, is by calling

FMOD::Channel* channel;
CoreSystem->getChannel(0, &channel);

But then calling

isPlaying = false;
this->channel->getPaused(&isPlaying);
this->channel->setPaused(!isPlaying);

is not working. It doesn’t stop the playback. And no, there is nothing in the output log.

The other way I thought of to get a channel was through:

FMOD::ChannelGroup* group;
this->AudioComp->StudioInstance->getChannelGroup(&group);
group->setPaused(isPlaying ? true : false);

and it does stop the stream, but when I want to unpause it, the only thing in output log is:

LogFMOD: e:\jk\workspace\2.1_UE4.25+_Win64\core_api\src\fmod_async.cpp(191) - Starting Asynchronous operation on sound 000002369E345608
LogFMOD: e:\jk\workspace\2.1_UE4.25+_Win64\core_api\src\fmod_async.cpp(336) - Finished Asynchronous operation on sound 000002369E345608

and the sound doesn’t return. I got the same result and the same output log when was calling:

this->AudioComp->SetPaused(isPlaying ? true : false);

So at the moment the only way of pausing the stream I see is by stopping the stream and creating a new one, just like in the initial post. Maybe there is another bug in UE4 streaming implementation or I’m doing something wrong.

You shouldn’t be trying to pause the channel, use AudioComponent::SetPaused to pause the event and the API will handle pausing/resuming all the channels of the event. If that doesn’t work, can you share the error logs you get from this?

I wrote twice that AudioComponent::SetPaused is not working and I wrote in the previous post that when I’m calling AudioComponent::SetPaused, there are no errors in the log, only:

LogFMOD: e:\jk\workspace\2.1_UE4.25+_Win64\core_api\src\fmod_async.cpp(191) - Starting Asynchronous operation on sound 000002369E345608
LogFMOD: e:\jk\workspace\2.1_UE4.25+_Win64\core_api\src\fmod_async.cpp(336) - Finished Asynchronous operation on sound 000002369E345608

This appears to be caused the the stream going virtual when it is paused, then when it comes back from virtual it wants to do a seek to get to the right spot however most netstreams don’t support seeking. You can work around this by setting the priority of the Event to ‘highest’ so that it won’t go virtual when paused.

Changing the event priority did the work. At the same time, it fixed a problem I was going to report (with stream not restarted when bus was set to 0 and reset to higher value), so we killed two birds with one stone.
Thanks a lot!

1 Like