Giter VIP home page Giter VIP logo

scpslaudioapi's Introduction

SCPSLAudioAPi

This is an API Library that does not depend on any Plugin frameworks for its function. This API provides a implementation of an Audio player in a SCP:SL Server with options to extend

Installation

Download the latest release from the Releases page and place the SCPSLAudioAPi.dll file in your plugin dependencies folder

Usage

Note: This is NOT an audioplayer plugin, this is a library to make creating a plugin that can play audio easier. To be able to play audio you will need to find a plugin that does that using this api, or a custom solution.

Developer Usage

The Library mainly consists of the AudioPlayerBase class, which can be inherited in combination with overriding Methods to create custom logic while still having the heavy lifting done by the Api.

Without a custom AudioPlayer class

Simply Create a Dummyplayer (Not included in the library) and Call AudioPlayerBase.Get() on the ReferenceHub of this DummyPlayer.

To play Audio, you must first, insert a Path to the audio file into the Queue, This can be done by directly modifying AudioToPlay, but it is recommend to use the Enqueue Method.
When audio is in the queue, call the Play method and after the file has been loaded, it should start playing your audio.

With a Custom AudioPlayer class

Simply Create a Dummyplayer (Not included in the library) and Call AudioPlayerBase.Get() on the ReferenceHub of this DummyPlayer.

(You will need to create a cusom NetworkConnection for a fake player)

public class FakeConnection : NetworkConnectionToClient
{
    public FakeConnection(int connectionId) : base(connectionId, false, 0f)
    {
            
    }

    public override string address
    {
        get
        {
            return "localhost";
        }
    }

    public override void Send(ArraySegment<byte> segment, int channelId = 0)
    {
    }
    public override void Disconnect()
    {
    }
}

then, you can spawn a fake player like this

var newPlayer = UnityEngine.Object.Instantiate(NetworkManager.singleton.playerPrefab);
var fakeConnection = new FakeConnection(id);
var hubPlayer = newPlayer.GetComponent<ReferenceHub>();
NetworkServer.AddPlayerForConnection(fakeConnection, newPlayer);

Then you can use the player like you would with any, eg spawn it, teleport it

Custom AudioPlayer classes work the same way as a normal AudioPlayerBase, the developer can change whatever they feel like in the methods for playing and broadcasting. Refer to the source of AudioPlayerBase to see what each method does.

You can get your AudioPlayer class in multiple ways You can try to find it in AudioPlayerBase.AudioPlayers, but it is recommended to create a helper Method.

public static CustomAudioPlayer Get(ReferenceHub hub)
{
    if (AudioPlayers.TryGetValue(hub, out AudioPlayerBase player))
    {
        if (player is CustomAudioPlayer cplayer1)
            return cplayer1;
    }

    var cplayer = hub.gameObject.AddComponent<CustomAudioPlayer>();
    cplayer.Owner = hub;

    AudioPlayers.Add(hub, cplayer);
    return cplayer;
}

Note: For Urls to work you must set AllowUrl to true on the AudioPlayerBase instance.

Features:

Volume control - AudioPlayerBase::Volume
Queue Looping - AudioPlayerBase::Loop
Queue Shuffle - AudioPlayerBase::Shuffle
Autoplay - AudioPlayerBase::Continue
Pausing - AudioPlayerBase::ShouldPlay
Play From URL - AudioPlayerBase::AllowUrl
Play to specific players only (Will play to everyone if the list is Empty) - AudioPlayerBase::BroadcastTo
Debug logs (can cause spam) - AudioPlayerBase::LogDebug AudioChannel - AudioPlayerBase::BroadcastChannel \

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.