[4.18] How to change volume of MediaPlayer playback?

anonymous_user_321bb538
Wed, 08 Nov 2017 20:50:36 +0000
Audio

I’m trying to implement multiple video playback on my VR application. I don’t know how to change the volume for specific separate MediaPlayer in C++. I’m working in UE 4.18.

User can dynamically import certain video from folder and display it as video player in 3D with controls panel: play/ pause/ volume slider. MediaPlayer creation is handled in C++ by wrapping it in my custom UObject-derived class.
Previous version of Media Framework allows me to control each video volume by changing it in UMediaSoundWave. Since UMediaSoundWave was replaced/integrated into UMediaSoundComponent i have no idea how to implement volme change properly.

I tried to create my own USoundClass and USoundMix and registering them in FAudioDevice:

Player	= NewObject< UMediaPlayer >( this );
...
SoundClass		= NewObject< USoundClass >( this );
SoundMix		= NewObject< USoundMix >( this );

FAudioDevice * audioDevice = FAudioDevice::GetMainAudioDevice();
if( audioDevice )
{
	audioDevice->RegisterSoundClass( SoundClass );
	audioDevice->PushSoundMixModifier( SoundMix );
}

Player->OpenFile( filepath );

then setting MediaPlayer and SoundClass in MediaSoundComponent:

this->SoundComponent	= CreateDefaultSubobject< UMediaSoundComponent >(TEXT("SoundComponent"));
this->SoundComponent->SetupAttachment(this->RootScene);
...

this->SoundComponent->MediaPlayer	= Player;
this->SoundComponent->SoundClass	= SoundClass;

so finally volume change is done like this:

if( !SoundClass )
	return;

FAudioDevice * audioDevice = FAudioDevice::GetMainAudioDevice();
if( audioDevice )
{
	audioDevice->SetSoundMixClassOverride( SoundMix, SoundClass, volume, 1.0f, 0.0f, false );
}

This code seems to not work, I can’t hear any volume change as an effect. How is the correct way to make this in new MediaFramework ?

9 posts - 5 participants