Developer Documentation
Our new developer documentation is now available. Please check it out!

OdinHandler.OnCreatedMediaObject

public UnityCreatedMediaObject OnCreatedMediaObject

Called if this OdinHandler created a MediaStream that was requested by the MediaQueue

Info

Invokes after OnMediaAdded

Value Type

TypeDescription
UnityCreatedMediaObject

Discussion

Whenever a “user (in ODIN language it’s a peer) has joined a room and starts sending audio data (i.e. has activated the microphone) this event is triggered after OnMediaAdded .

You can respond to this event and call the AddPlaybackComponent function of the OdinHandler.Instance like shown in the example below.

Your callback function must have this structure and contains information about the room, peer and the media object.

public class UnityCreatedMediaObject : UnityEvent<string, ulong, int>;

Whenever this callback is triggered, imagine a new player comes in the arena and the game master needs to give him a Walky Talky so that he can listen and talk to the other players.

Example

OnCreatedMediaObject Example
private void OnCreatedMediaObject(string roomName, ulong peerId, ushort mediaId)
{
    Room room = OdinHandler.Instance.Rooms[roomName];
    if (room == null || room.Self == null || room.Self.Id == peerId) return;

    // Find the players game object in the scene
    var peerContainer = FindPlayerForPeerId(peerId);

    // Add PlaybackComponent to new dummy PeerCube
    PlaybackComponent playback = OdinHandler.Instance.AddPlaybackComponent(peerContainer, room.Config.Name, peerId, mediaId);

    // Some AudioSource test settings
    playback.PlaybackSource.spatialBlend = 1.0f;
    playback.PlaybackSource.rolloffMode = AudioRolloffMode.Linear;
    playback.PlaybackSource.minDistance = 1;
    playback.PlaybackSource.maxDistance = 10;
}