docs.unity3d.com
    Show / Hide Table of Contents

    Media Player

    The media player in the IVI interface uses several custom scripts.

    HMI_MediaController

    This script is the main script for controlling and displaying albums (Playlist) and songs (Tracklist). To use the script you specify the parent object for each Playlist and Tracklist. You also spcify which Prefab you want to instantiate when an entry is created. The Music Player Script must exist for the script to function.

    There are also fields that you can use to display album art (Cover).

    HMI_PlaylistEntryHelper

    The demo project places this script on the parent object for the Prefab it uses as a Tracklist Entry. The script handles how the system sets internal information and processes button clicks. The script contains more information and methods than Playlist entries.

    HMI_PlayheadUI

    This script lets the interface visualize media playback. It uses Delegate Events as triggers to update information from the MusicPlayer. You must place the script on the parent object of the Playback/Playhead Prefab.

    The script also processes button clicks on the Pause/Play button, located in the PlayheadUI Prefab.

    GetMusicFrom StreamingAssetsFolder script

    On Play, this script generates a list of albums, songs, and album art. Folders in your Assets > StreamingAssets > Music are considered your Albums. Inside these folders there must be:

    • One Album Art (supported format .png or .jpg).
    • Your music (supported format .wav, .mp3. and .ogg).

    Music Player Script

    The Music Player script targets an audio source and pull the music list from the GetMusicFromStreamingAssetsFolder script.

    The Music Player tracks the Current Song Data in a class to make it easier to manipulate songs.

    Important public methods in Music Player Script:

    • PlayPauseAudioSource()
    • StopMusicClip()
    • NextSong()
    • PreviousSong()
    • SetAlbum(string AlbumName)
    • SetAlbumWithDesiredSongAndPlay(string AlbumName, int DesiredSongIndex)
    • PlayAudioFromPath(string path) – Sets audio and plays
    • SetAudioFromPath(string path) - Sets audio without playing
    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on September 15, 2021