Our new developer documentation is now available. Please check it out!
OdinHandler.OnMediaRemoved
public MediaRemovedProxy OnMediaRemoved
Called on every Peer that closed/destroyed one of his own media in the same room(s)
Info
Invokes before OnDeleteMediaObject
Value Type
Type | Description |
---|---|
MediaRemovedProxy |
Discussion
Whenever a “user (in ODIN language it’s a peer) stops sending audio data (i.e. has deactivated the microphone) this event is triggered.
Your callback function must have this structure. MediaRemovedEventArgs contains information about the peer and the media removed from the room:
public void OnMediaRemoved(object sender, MediaRemovedEventArgs eventArgs);
You need to respond to this event and you need to remove the PlaybackComponent that you have attached to a game object before in the OnMediaAdded callback. You also need to remove the AudioSource from the Game Object which has been created by ODIN automatically.
Example
OnMediaRemoved Example
using OdinNative.Odin;
using OdinNative.Odin.Room;
using OdinNative.Unity;
using OdinNative.Unity.Audio;
using UnityEngine;
public class MyOdinPeerManager : MonoBehaviour
{
public void RemoveOdinPlaybackFromPlayer(PlayerScript player)
{
// Remove the PlaybackComponent and the AudioSource
PlaybackComponent playback = player.GetComponent<PlaybackComponent>();
Destroy(playback);
AudioSource audioSource = player.GetComponent<AudioSource>();
Destroy(audioSource);
}
public void OnMediaRemoved(object sender, MediaRemovedEventArgs eventArgs)
{
// Called when the peer stops sending audio
Room room = sender as Room;
Debug.Log($"ODIN MEDIA REMOVED. Room: {room.Config.Name}, MediaId: {eventArgs.Media.Id}, UserData: {eventArgs.Peer.UserData.ToString()}");
// Use the User Data to to map the ODIN peer to the player in the network
CustomUserDataJsonFormat userData = CustomUserDataJsonFormat.FromUserData(eventArgs.Peer.UserData);
PlayerScript player = GetPlayerForOdinPeer(userData);
if (player)
{
RemoveOdinPlaybackFromPlayer(player);
}
}
}