The basic setup:
In .h:
UMediaPlayer* MediaPlayer;
UMediaSoundComponent* NewMediaSoundComponent;
In .cpp BeginPlay():
MediaPlayer = NewObject<UMediaPlayer>(this);
NewMediaSoundComponent = NewObject<UMediaSoundComponent>(this);
NewMediaSoundComponent->SetMediaPlayer(MediaPlayer);
Called from a button:
void AMyPlayerController::stopPressed(UShawnButton* buttonSent) {
UMediaPlayer *tempPlayer=NewMediaSoundComponent->GetMediaPlayer();
if (tempPlayer) {
UKismetSystemLibrary::PrintString(this, TEXT("tempPlayer Exists"), true, true, FLinearColor(.7, 0, .5, 1), 200.0);
} else {
UKismetSystemLibrary::PrintString(this, TEXT("NOT tempPlayer"), true, true, FLinearColor(.7, 0, .5, 1), 200.0);
}
if (MediaPlayer) {
UKismetSystemLibrary::PrintString(this, TEXT("MediaPlayer Exists"), true, true, FLinearColor(.7, 0, .5, 1), 200.0);
} else {
UKismetSystemLibrary::PrintString(this, TEXT("NOT MediaPlayer"), true, true, FLinearColor(.7, 0, .5, 1), 200.0);
}
tempPlayer->Close(); //!ERROR in multiplayer
MediaPlayer->Close(); //!ERROR
}
When this is run with 1 player selected for PIE calling the function shows that both tempPlayer and MediaPlayer exist. However MediaPlayer will throw an exception error if you try to call something on it (like Close()).
If you change PIE to 2 players this function shows neither templayer or MediaPlayer exist for the first client (server). The second client does have them both although neither times have I been able to actually load and play audio with it.
I’m trying to update a program working in 4.18 to see if some of the problems with mediaplayer have been fixed (choppy first second of play, no event for song end) and previously you could test with 2 clients and whichever one you clicked on it played the audio and muted the other. It would be really hard to keep testing if this isn’t fixed since I’m trying to send custom audio files over tcp and play them.