Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.P) == true)
     {
         songPlayer.PlaySong("Assets/Audio/Seventeen Years-Ratatat.mp3");
     }
 }
    private IEnumerator Import(string path)
    {
        m_isImporting = true;

        while (m_uiSound.isPlaying)
        {
            yield return(null);
        }

        TagLib.File tagFile = TagLib.File.Create(path);

        m_currentArtist = tagFile.Tag.JoinedPerformers;
        m_currentTitle  = tagFile.Tag.Title;

        int foundFirstImageIndex = -1;

        for (int i = 0; i < tagFile.Tag.Pictures.Length; i++)
        {
            if (tagFile.Tag.Pictures[i].MimeType == "image/png" || tagFile.Tag.Pictures[i].MimeType == "image/jpeg")
            {
                foundFirstImageIndex = i;
                break;
            }
        }

        if (foundFirstImageIndex != -1)
        {
            var       bin = (byte[])(tagFile.Tag.Pictures[foundFirstImageIndex].Data.Data);
            Texture2D tex = new Texture2D(2, 2);
            tex.LoadImage(bin);
            tex.Apply();

            m_albumArtDisplay.texture = tex;
        }
        else
        {
            m_albumArtDisplay.texture = m_defaultImage;
        }

        if (m_currentTitle != null && m_currentArtist != null)
        {
            m_nowPlayingText.text = $"{m_currentArtist} - {m_currentTitle}";
        }
        else if (m_currentTitle != null && m_currentArtist == null)
        {
            m_nowPlayingText.text = $"{m_currentTitle}";
        }
        else
        {
            m_nowPlayingText.text = $"{Path.GetFileName(m_currentFilePath)}";
        }

        m_importer.Import(path);

        while (!m_importer.isDone)
        {
            yield return(null);
        }

        m_isImporting = false;
        m_songPlayer.PlaySong(m_importer.audioClip);
    }