Beispiel #1
0
    public SoundPlayer(byte[] data)
    {
        gameObject = new GameObject("Sound");
        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.clip = AudioCompression.Decompress(data, gameObject.AddComponent <CoroutineMonoBehaviour>());
        source.Play();
    }
Beispiel #2
0
 /// <summary>
 /// Create an Album with associated metadata
 /// </summary>
 /// <param name="title"></param>
 /// <param name="artist"></param>
 /// <param name="genre"></param>
 /// <param name="releaseYear"></param>
 /// <param name="compression"></param>
 public Album(string title, Artist artist, string genre, int releaseYear, AudioCompression compression)
 {
     Title = title;
     Artist = artist;
     Genre = genre;
     ReleaseYear = releaseYear;
     CoverArt = IMPORTED_COVERART;
     Compression = compression;
 }
Beispiel #3
0
 /// <summary>
 /// Create an Album with associated metadata
 /// </summary>
 /// <param name="title"></param>
 /// <param name="artist"></param>
 /// <param name="genre"></param>
 /// <param name="releaseYear"></param>
 /// <param name="compression"></param>
 public Album(string title, Artist artist, string genre, int releaseYear, AudioCompression compression)
 {
     Title       = title;
     Artist      = artist;
     Genre       = genre;
     ReleaseYear = releaseYear;
     CoverArt    = IMPORTED_COVERART;
     Compression = compression;
 }
Beispiel #4
0
    public void Init()
    {
        audioSource             = gameObject.AddComponent <AudioSource>();
        audioSource.volume      = 0;
        audioSource.loop        = playMode == PlayMode.LOOP || playMode == PlayMode.BKGND;
        audioSource.playOnAwake = false;

        if (soundData.bytes.Length == 0)
        {
            return;
        }
        audioSource.clip = AudioCompression.Decompress(soundData.bytes, this);

        if (playMode != PlayMode._1SHOT)
        {
            StartCoroutine(VolumeUpdateCoroutine());
        }
    }
Beispiel #5
0
    public void ReadStream(Stream stream)
    {
        FileStream fs = stream as FileStream;

        if (fs == null)
        {
            throw new MapReadException("Can't read audio from this location");
        }
        string path = fs.Name;

        // TODO is this bad? closing the file so web request can read from it
        // ReadStream isn't supposed to dispose the stream
        fs.Close();
        Debug.Log("Loading audio from " + path);

        // TODO file type
        UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file://"
                                                                     + System.Uri.EscapeUriString(path), audioType);
        var stopwatch = new System.Diagnostics.Stopwatch();

        stopwatch.Start();
        var asyncOp = www.SendWebRequest();

        // TODO this seems like a very bad idea
        while (!asyncOp.isDone)
        {
            System.Threading.Thread.Sleep(10);
        }
        stopwatch.Stop();
        Debug.Log("Loading audio took " + stopwatch.ElapsedMilliseconds);
        if (www.error != null)
        {
            throw new MapReadException(www.error);
        }
        AudioClip clip = DownloadHandlerAudioClip.GetContent(www);

        if (clip == null || clip.samples == 0)
        {
            throw new MapReadException("Unable to read audio (unsupported format?)");
        }

        byte[] bytes = AudioCompression.Compress(clip);
        data = new EmbeddedData(Path.GetFileNameWithoutExtension(path), bytes, EmbeddedDataType.Audio);
    }
Beispiel #6
0
    public void Init()
    {
        audioSource              = gameObject.AddComponent <AudioSource>();
        audioSource.volume       = 0;
        audioSource.loop         = playMode == PlayMode.LOOP || playMode == PlayMode.BKGND;
        audioSource.spatialBlend = spatial ? 1.0f : 0.0f;
        if (spatial)
        {
            audioSource.minDistance = minDistance;
            audioSource.spread      = spatialMode == SpatialSoundMode.AMBIENT ? 180 : 0;
        }
        audioSource.playOnAwake = false;

        if (soundData.bytes.Length == 0)
        {
            return;
        }
        audioSource.clip = AudioCompression.Decompress(soundData.bytes, this);

        if (playMode != PlayMode._1SHOT)
        {
            StartCoroutine(VolumeUpdateCoroutine());
        }
    }