LibRPMedia

LibRPMedia

3.4k Downloads

Add method to obtain API-native music file ID/path

Meorawr opened this issue ยท 0 comments

commented

Classic hasn't had the API support for file IDs backported. As each including addon is going to have to insert an "if classic then use path else use id" type check as a result, we should put in a utility function that automates that step.

Prototype:

function LibRPMedia:GetNativeMusicFile(musicFile) end

Description:

Returns an API-native file reference for the given music file ID. The return value from this function is safe for usage with Blizzard APIs such as PlaySoundFile and PlayMusic.

The return value should be treated as opaque data; its type may vary based upon what client version is in use.

Usage:

local musicFile = LibRPMedia:GetMusicFileByName("citymusic/darnassus/darnassus intro");
local nativeFile = LibRPMedia:GetNativeMusicFile(musicFile);
PlayMusic(nativeFile); -- Should play the music.

Example implementation:

function LibRPMedia:GetNativeMusicFile(musicFile)
    if IsClassicClient() then
        local musicName = self:GetMusicNameFromFile(musicFile);
        return strjoin("\\", "Sound", "Music", strsplit("/", musicName)) .. ".mp3";
    end

    return musicFile;
end