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