I am writing a script currently, and I want to know when a song has ended so I can start a new one. This did not seem possible with the default Audio class, so I tried using Behemoth's SAudio module:
#######################
# Script by: BEHEMOTH #
# #######################################################
# #
# Script: SAudio Module #
# Current Version: 2.1 #
# #
# * Version 2.1 #
# - Can now Fade In/Out Audio #
# #
# * Version 2.0 #
# - Bug Fixes #
# - Can now start the beginning loop at any position #
# - Can now get how many times an audio file has continued playing #
# #
# * Version 1.0 #
# - Ability to control audio by: #
# - panning volume #
# - pause/resume #
# - Start Play Position #
# - Loop Audio #
# - Seek to Position #
# - Retrieving Properties (volume/panning/position/title/etc...) #
# #
#############################################################################
#############################################################################
# ***Main Commands*** #
# The commands with a star beside them require a sub command. #
# Detailed comments on each command can be found below in the comment boxes.#
# #
# SAudio.bgm_load(filename, volume, pan, start_pos, loop_pos) #
# SAudio.bgs_load(filename, volume, pan, start_pos, loop_pos) #
# SAudio.memorize_bgm #
# SAudio.restore_memorized_bgm #
# SAudio.memorize_bgs #
# SAudio.restore_memorized_bgs #
# SAudio.me_play(filename, volume, pan, start_pos) #
# SAudio.me_stop #
# SAudio.se_play(filename, volume, pan, start_pos) #
# SAudio.se_stop #
# SAudio.all_stop #
# * SAudio.bgm #
# * SAudio.bgs #
# #
# ***Sub Commands*** #
# play(pos) #
# seek(pos) #
# pause #
# resume #
# stop #
# volume_set(volume) #
# pan_set(pan_percent) #
# status #
# length_hour #
# length_min #
# length_sec #
# length_ms #
# length_total_sec #
# pos_hour #
# pos_min #
# pos_sec #
# pos_ms #
# pos_total_sec #
# pos_percent #
# #
# #
# ***Example of Loading and Playing Audio*** #
# #
# 1) First load your audio by using one of the load commands or se_play. #
# Fill in the parameters (the words inside the brackets) with the #
# values you want for each. #
# SAudio.bgm_load(filename, volume, pan, start_pos, loop) #
# Example: SAudio.bgm_load('Town.wav', 100, 0, 0, true) #
# #
# 2) Then type the bgm's command to access the bgm's functions. #
# Example: SAudio.bgm_load('Town.wav', 100, 0, 0, true) #
# SAudio.bgm #
# #
# 3) Followed by a . then a sub command to use it's function. #
# Example: SAudio.bgm_load('Town.wav', 100, 0, 0, true) #
# SAudio.bgm.play #
# #
# 4) There....you just loaded and played a bgm audio file. Use other sub #
# commands to get or set properties of the audio. #
# #
#############################################################################
#===========================================================================
class SAudioFile
attr_reader :id
attr_reader :filename
attr_reader :playkind
attr_reader :dirpath
attr_reader :volume
attr_reader :pan
attr_reader :start_pos
attr_reader :loop_pos
attr_reader :fadein_time
attr_reader :start_fadein_time
attr_accessor :fadeout_time
attr_accessor :start_fadeout_time
attr_accessor :play_count
#-------------------------------------------------------------------------
# Object Initialization
# id : Audio ID (Min)0..20(Max)
# type : Audio Type (0=BGM 1=BGS 2=ME 3=SE)
# filename : Audio Filename (Must Include File Extension)
# Volume : Audio Volume (Off)0..100(On)
# Pan : Audio Pan Volume (Left Speaker)-100..100(Right Speaker)
# fadein_time : length of the fadeout (In Frames)
# start_pos : Audio Start Position (In Milliseconds)
# loop_pos : Loop Start Position (In Milliseconds. < 0 = no loop)
#-------------------------------------------------------------------------
def initialize(id, type, filename, volume, pan, start_pos, fadein_time, loop_pos)
@id = id
@filename = filename
case type
when 0
@dirpath = "Audio/BGM/"
when 1
@dirpath = "Audio/BGS/"
when 2
@dirpath = "Audio/ME/"
else
@dirpath = "Audio/SE/"
end
@fadein_time = fadein_time
@start_fadein_time = fadein_time
@start_fadeout_time = 0
@fadeout_time = 0
@start_pos = start_pos
@loop_pos = loop_pos
@play_count = 0
@playkind = type
@force_done = false
volume_set(volume, pan)
end
#-------------------------------------------------------------------------
# Plays Audio [Returns Bool - True if successful, false otherwise]
# pos: New Play Position (In Milliseconds)
#-------------------------------------------------------------------------
def play(pos=nil)
SAudio.load(@id, @dirpath, @filename)
if pos == nil
result = SAudio.play(@id, @start_pos)
else
pos = length_ms if pos >= length_ms
result = SAudio.play(@id, pos)
end
@fadein_time = @start_fadein_time
@start_fadeout_time = 0
@fadeout_time = 0
volume_set(@volume)
return result
end
#-------------------------------------------------------------------------
# Audio Seek (Moves the current playing position to the specified position)
# Stops Audio if playing.
# pos: New Play Position (In Milliseconds)
#-------------------------------------------------------------------------
def seek(pos)
pos = length_ms if pos >= length_ms
SAudio.seek(@id, pos)
end
#-------------------------------------------------------------------------
# Pauses Audio
#-------------------------------------------------------------------------
def pause
SAudio.pause(@id)
end
#-------------------------------------------------------------------------
# Resumes Audio
#-------------------------------------------------------------------------
def resume
SAudio.resume(@id)
end
#-------------------------------------------------------------------------
# Stops Audio
#-------------------------------------------------------------------------
def stop
SAudio.stop(@id)
end
#-------------------------------------------------------------------------
# Starts fadeout. time is the length of the fadeout in Frames.
#-------------------------------------------------------------------------
def fade(time)
@start_fadeout_time = time
@fadeout_time = time
end
#-------------------------------------------------------------------------
# Set Audio Volume
# volume : (Off)0..100(On)
# pan_percent : (Left)-100..100(Right)
#-------------------------------------------------------------------------
def volume_set(volume, pan_percent=nil)
@volume = [[volume, 0].max, 100].min
if @fadein_time > 0
fade_percent = 100 - ((@fadein_time.to_f / @start_fadein_time.to_f) * 100).truncate
@fade_volume = @volume - (@volume * (fade_percent.to_f / 100)).truncate
elsif @fadeout_time > 0
fade_percent = 100 - ((@fadeout_time.to_f / @start_fadeout_time.to_f) * 100).truncate
@fade_volume = (@volume * (fade_percent.to_f / 100)).truncate
else
@fade_volume = 0
end
pan = pan_percent==nil ? @pan : pan_percent
pan_set(pan)
end
#-------------------------------------------------------------------------
# Set Audio Left Volume
# Volume: (Off)0..100(On)
#-------------------------------------------------------------------------
def volumeleft_set(volume)
@volumeleft = [[volume, 0].max, 100].min
SAudio.l_volume(@id, @volumeleft)
end
#-------------------------------------------------------------------------
# Set Audio Right Volume
# Volume: (Off)0..100(On)
#-------------------------------------------------------------------------
def volumeright_set(volume)
@volumeright = [[volume, 0].max, 100].min
SAudio.r_volume(@id, @volumeright)
end
#-------------------------------------------------------------------------
# Pan Audio
# Pan Percent: (Left)-100..100(Right)
#-------------------------------------------------------------------------
def pan_set(pan_percent)
volume = @volume-@fade_volume
@pan = [[pan_percent, -100].max, 100].min
vleft = @pan < 0 ? 100 : 100 - @pan
vleft = ((vleft * volume) / 100).truncate
vright = @pan < 0 ? 100 + @pan : 100
vright = ((vright * volume) / 100).truncate
volumeleft_set(vleft)
volumeright_set(vright)
end
#-------------------------------------------------------------------------
# Get Audio Status [Returns String]
# Returns 1 of the following strings:
# Paused
# Playing
# Stopped
# Seeking
#-------------------------------------------------------------------------
def status
return SAudio.status(@id)
end
#-------------------------------------------------------------------------
# Get Audio Length (Hours) [Returns Numeric]
#-------------------------------------------------------------------------
def length_hour
time = SAudio.get_length_hms(@id)
return time[0]
end
#-------------------------------------------------------------------------
# Get Audio Length (Minutes) [Returns Numeric]
#-------------------------------------------------------------------------
def length_min
time = SAudio.get_length_hms(@id)
return time[1]
end
#-------------------------------------------------------------------------
# Get Audio Length (Seconds) [Returns Numeric]
#-------------------------------------------------------------------------
def length_sec
time = SAudio.get_length_hms(@id)
return time[2]
end
#-------------------------------------------------------------------------
# Get Audio Length (MilliSeconds) [Returns Numeric]
#-------------------------------------------------------------------------
def length_ms
return SAudio.get_length_ms(@id)
end
#-------------------------------------------------------------------------
# Get Audio Length (Total Seconds) [Returns Numeric]
#-------------------------------------------------------------------------
def length_total_sec
ms_length = SAudio.get_length_ms(@id)
return (ms_length.to_f / 1000).round
end
#-------------------------------------------------------------------------
# Get Audio Position (Hours) [Returns Numeric]
#-------------------------------------------------------------------------
def pos_hour
time = SAudio.get_pos_hms(@id)
return time[0]
end
#-------------------------------------------------------------------------
# Get Audio Position (Minutes) [Returns Numeric]
#-------------------------------------------------------------------------
def pos_min
time = SAudio.get_pos_hms(@id)
return time[1]
end
#-------------------------------------------------------------------------
# Get Audio Position (Seconds) [Returns Numeric]
#-------------------------------------------------------------------------
def pos_sec
time = SAudio.get_pos_hms(@id)
return time[2]
end
#-------------------------------------------------------------------------
# Get Audio Position (MilliSeconds) [Returns Numeric]
#-------------------------------------------------------------------------
def pos_ms
return SAudio.get_pos_ms(@id)
end
#-------------------------------------------------------------------------
# Get Audio Position (Total Seconds) [Returns Numeric]
#-------------------------------------------------------------------------
def pos_total_sec
pos = SAudio.get_pos_ms(@id)
return (pos.to_f / 1000).round
end
#-------------------------------------------------------------------------
# Get Audio Position (Percentage) [Returns Numeric]
#-------------------------------------------------------------------------
def pos_percent
pos = SAudio.get_pos_ms(@id)
pos_sec = pos.to_f / 1000
time = SAudio.get_length_ms(@id)
total_sec = time.to_f / 1000
return 0 if pos_sec == 0 || total_sec == 0
percent = ((pos_sec / total_sec) * 100).round
return percent
end
#-------------------------------------------------------------------------
# Updates Audio
#-------------------------------------------------------------------------
def update
if status == 'Playing'
#Audio fading in
if @fadein_time > 0
volume_set(@volume)
@fadein_time -= 1
#Audio fading out
elsif @fadeout_time > 0
volume_set(@volume)
#@force_done = true if @fadeout_time == 1
@fadeout_time -= 1
if @fadeout_time == 0
if @playkind == 2
@force_done = true
else
stop
return
end
end
end
#Audio is completed
if pos_ms >= length_ms or @force_done
@force_done = false
@play_count+=1
if @loop_pos >= 0
play(@loop_pos)
else
#ME Completed - Resume bgm
if @playkind == 2
if SAudio.me_bgm_resume?
SAudio.bgm.resume
end
end
stop
end
end
end
end
#-------------------------------------------------------------------------
end
#===========================================================================
module SAudio
MAX_AUDIOS = 20 #Maximum number of SAudioFiles that can be played
MEMBGM_ID = 0
MEMBGS_ID = 1
BGM_ID = 2
BGS_ID = 3
ME_ID = 4
START_SE_ID = 5
@se_id = START_SE_ID #to MAX_AUDIOS
@audios = []
@media = Win32API.new('winmm', 'mciSendString', 'ppll', 'V')
module_function
#===========================================================================
# Specific Audio Functions
#===========================================================================
#-------------------------------------------------------------------------
# Updates All Audio
#-------------------------------------------------------------------------
def update
for id in BGM_ID...MAX_AUDIOS
unless @audios[id].nil?
@audios[id].update
end
end
end
#-------------------------------------------------------------------------
# Loads BGM Audio
# filename : Audio Filename (with extension)
# volume : Audio Volume (Off)0..100(On)
# pan : Audio Pan Volume (Left)-100..100(Right)
# start_pos : Start Position of Audio when played
# fadein_time : length of the fadein (In Frames)
# loop_pos : Loop Start Position
#-------------------------------------------------------------------------
def bgm_load(filename, volume=100, pan=0, start_pos=0, fadein_time=0, loop_pos=0)
@audios[BGM_ID] = SAudioFile.new(BGM_ID, 0, filename, volume, pan, start_pos, fadein_time, loop_pos)
end
#-------------------------------------------------------------------------
# Get BGM Audio [Returns SAudioFile]
#-------------------------------------------------------------------------
def bgm
if @audios[BGM_ID].nil?
bgm_load("")
end
return @audios[BGM_ID]
end
#-------------------------------------------------------------------------
# Loads Memorized BGM Audio from BGM
#-------------------------------------------------------------------------
def memorize_bgm
@audios[MEMBGM_ID] = SAudioFile.new(MEMBGM_ID, 0, bgm.filename, bgm.volume,
bgm.pan, bgm.start_pos, bgm.fadein_time, bgm.loop_pos)
@audios[MEMBGM_ID].play_count = bgm.play_count
@audios[MEMBGM_ID].fadeout_time = bgm.fadeout_time
@audios[MEMBGM_ID].start_fadeout_time = bgm.start_fadeout_time
@membgm_pos = bgm.pos_ms
@membgm_status = bgm.status
end
#-------------------------------------------------------------------------
# Restores BGM Audio from Memorized BGM Audio
#-------------------------------------------------------------------------
def restore_memorized_bgm
if memorized_bgm != nil
bgm_load(memorized_bgm.filename, memorized_bgm.volume, memorized_bgm.pan,
memorized_bgm.start_pos, memorized_bgm.loop_pos)
bgm.play_count = memorized_bgm.play_count
bgm.fadeout_time = memorized_bgm.fadeout_time
bgm.start_fadeout_time = memorized_bgm.start_fadeout_time
if @membgm_status == 'Playing'
bgm.play(@membgm_pos)
elsif @membgm_status == 'Paused' or @membgm_status == 'Seeking'
bgm.seek(@membgm_pos)
bgm.pause
end
end
end
#-------------------------------------------------------------------------
# Get Memorized BGM Audio [Returns SAudioFile]
#-------------------------------------------------------------------------
def memorized_bgm
return @audios[MEMBGM_ID]
end
#-------------------------------------------------------------------------
# Loads BGS Audio
# filename : Audio Filename (with extension)
# volume : Audio Volume (Off)0..100(On)
# pan : Audio Pan Volume (Left)-100..100(Right)
# start_pos : Start Position of Audio when played
# fadein_time : length of the fadein (In Frames)
# loop_pos : Loop Start Position
#-------------------------------------------------------------------------
def bgs_load(filename, volume=100, pan=0, start_pos=0, fadein_time=0, loop_pos=0)
@audios[BGS_ID] = SAudioFile.new(BGS_ID, 1, filename, volume, pan, start_pos, fadein_time, loop_pos)
end
#-------------------------------------------------------------------------
# Get BGS Audio [Returns SAudioFile]
#-------------------------------------------------------------------------
def bgs
if @audios[BGS_ID].nil?
bgs_load("")
end
return @audios[BGS_ID]
end
#-------------------------------------------------------------------------
# Loads Memorized BGS Audio from BGS
#-------------------------------------------------------------------------
def memorize_bgs
@audios[MEMBGS_ID] = SAudioFile.new(MEMBGS_ID, 0, bgs.filename, bgs.volume,
bgs.pan, bgs.start_pos, bgs.fadein_time, bgs.loop_pos)
@audios[MEMBGS_ID].play_count = bgs.play_count
@audios[MEMBGS_ID].fadeout_time = bgs.fadeout_time
@audios[MEMBGS_ID].start_fadeout_time = bgs.start_fadeout_time
@membgs_pos = bgs.pos_ms
@membgs_status = bgs.status
end
#-------------------------------------------------------------------------
# Restores BGS Audio from Memorized BGS Audio
#-------------------------------------------------------------------------
def restore_memorized_bgs
if memorized_bgs != nil
bgs_load(memorized_bgs.filename, memorized_bgs.volume, memorized_bgs.pan,
memorized_bgs.start_pos, memorized_bgs.loop_pos)
bgs.play_count = memorized_bgs.play_count
bgs.fadeout_time = memorized_bgs.fadeout_time
bgs.start_fadeout_time = memorized_bgs.start_fadeout_time
if @membgs_status == 'Playing'
bgs.play(@membgs_pos)
elsif @membgs_status == 'Paused' or @membgs_status == 'Seeking'
bgs.seek(@membgs_pos)
bgs.pause
end
end
end
#-------------------------------------------------------------------------
# Get Memorized BGS Audio [Returns SAudioFile]
#-------------------------------------------------------------------------
def memorized_bgs
return @audios[MEMBGS_ID]
end
#-------------------------------------------------------------------------
# Get ME Audio [Returns SAudioFile]
#-------------------------------------------------------------------------
def me
return @audios[ME_ID]
end
#-------------------------------------------------------------------------
# Plays ME Audio
# filename : Audio Filename (with extension)
# volume : Audio Volume (Off)0..100(On)
# pan : Audio Pan Volume (Left)-100..100(Right)
# start_pos : Start Position of Audio when played (In Milliseconds)
# fadein_time : length of the fadein (In Frames)
#-------------------------------------------------------------------------
def me_play(filename, volume=100, pan=0, start_pos=0, fadein_time=0)
@audios[ME_ID] = SAudioFile.new(ME_ID, 2, filename, volume, pan, start_pos, fadein_time, -1)
if @audios[ME_ID].status == 'Stopped'
@me_resume = false
if bgm.status == 'Playing'
@me_resume = true
end
end
bgm.pause
me.play
end
#-------------------------------------------------------------------------
# Starts ME fadeout. time is the length of the fadeout in Frames.
#-------------------------------------------------------------------------
def me_fade(time)
me.fade(time)
end
#-------------------------------------------------------------------------
# Gets if the BGM will resume or not at the end of the ME
#-------------------------------------------------------------------------
def me_bgm_resume?
return @me_resume
end
#-------------------------------------------------------------------------
# Stops ME Audio
#-------------------------------------------------------------------------
def me_stop
me.stop
end
#-------------------------------------------------------------------------
# Plays SE Audio
# filename : Audio Filename (with extension)
# volume : Audio Volume (Off)0..100(On)
# pan : Audio Pan Volume (Left)-100..100(Right)
# start_pos : Start Position of Audio when played
# fadein_time : length of the fadein (In Frames)
#-------------------------------------------------------------------------
def se_play(filename, volume=100, pan=0, start_pos=0, fadein_time=0)
@audios[@se_id] = SAudioFile.new(@se_id, 3, filename, volume, pan, start_pos, fadein_time, -1)
@audios[@se_id].play
@se_id += 1
if @se_id >= MAX_AUDIOS
@se_id = START_SE_ID
end
end
#-------------------------------------------------------------------------
# Stops All SE Audio
#-------------------------------------------------------------------------
def se_stop
for i in START_SE_ID...MAX_AUDIOS
if @audios[i] != nil
@audios[i].stop
end
end
end
#-------------------------------------------------------------------------
# Stops All Audio
#-------------------------------------------------------------------------
def all_stop
for i in BGM_ID...MAX_AUDIOS
if @audios[i] != nil
@audios[i].stop
end
end
end
#-------------------------------------------------------------------------
#===========================================================================
# General Audio Functions
#===========================================================================
#-------------------------------------------------------------------------
# Loads Audio ID [Returns Bool - True if successful, false otherwise]
# id : Audio ID
# dirname : directory
# filename : filename(with extension)
#-------------------------------------------------------------------------
def load(id, dirname, filename)
stop(id)
filepath = dirname+filename
if FileTest.exist?(filepath) == false
print("Error: #{filepath} does not exist!")
return false
end
s = "open " + filepath + " shareable type MPEGVideo alias sAudio#{id}"
@media.call(s, 0, 0, 0)
return true
end
#-------------------------------------------------------------------------
# Plays Audio ID
# id : Audio ID
# start_pos : Start Position of Audio when played
#-------------------------------------------------------------------------
def play(id, start_pos)
seek(id, start_pos)
@media.call("play sAudio#{id}", 0, 0, 0)
end
#-------------------------------------------------------------------------
# Audio ID Seek - Stops Audio if playing.
# id : Audio ID
# pos : New Play Position (In Milliseconds)
#-------------------------------------------------------------------------
def seek(id, pos)
@media.call("set sAudio#{id} seek exactly on", 0, 0, 0)
@media.call("seek sAudio#{id} to " + pos.to_s, 0, 0, 0)
end
#-------------------------------------------------------------------------
# Pauses Audio ID
# id : Audio ID
#-------------------------------------------------------------------------
def pause(id)
@media.call("pause sAudio#{id}", 0, 0, 0)
end
#-------------------------------------------------------------------------
# Resumes Audio ID
# id : Audio ID
#-------------------------------------------------------------------------
def resume(id)
@media.call("resume sAudio#{id}", 0, 0, 0)
end
#-------------------------------------------------------------------------
# Stops Audio ID
# id : Audio ID
#-------------------------------------------------------------------------
def stop(id)
@media.call("close sAudio#{id}", 0, 0, 0)
end
#-------------------------------------------------------------------------
# Set Audio ID Volume
# id : Audio ID
# Volume: (Off)0..100(On)
#-------------------------------------------------------------------------
def volume(id, volume)
volume *= 10
@media.call("setaudio sAudio#{id} volume to " + volume.to_s, 0, 0, 0)
end
#-------------------------------------------------------------------------
# Set Audio ID Left Volume
# id : Audio ID
# Volume: (Off)0..100(On)
#-------------------------------------------------------------------------
def l_volume(id, volume)
volume *= 10
@media.call("setaudio sAudio#{id} left volume to " + volume.to_s, 0, 0, 0)
end
#-------------------------------------------------------------------------
# Set Audio ID Right Volume
# id : Audio ID
# Volume: (Off)0..100(On)
#-------------------------------------------------------------------------
def r_volume(id, volume)
volume *= 10
@media.call("setaudio sAudio#{id} right volume to " + volume.to_s, 0, 0, 0)
end
#-------------------------------------------------------------------------
# Get Audio ID Right Volume [Returns Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_r_volume(id)
status = " " * 255
@media.call("status sAudio#{id} right volume", status, 255, 0)
status = (status.to_i / 10).truncate
return status
end
#-------------------------------------------------------------------------
# Get Audio ID Left Volume [Returns Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_l_volume(id)
status = " " * 255
@media.call("status sAudio#{id} left volume", status, 255, 0)
status = (status.to_i / 10).truncate
return status
end
#-------------------------------------------------------------------------
# Get Audio ID Volume [Returns Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_volume(id)
status = " " * 255
@media.call("status sAudio#{id} volume", status, 255, 0)
status = (status.to_i / 10).truncate
return status
end
#-------------------------------------------------------------------------
# Get Audio ID Length (Milliseconds) [Returns Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_length_ms(id)
time = " " * 255
@media.call("status sAudio#{id} length", time, 255, 0)
return time.to_i
end
#-------------------------------------------------------------------------
# Get Audio ID Length (hh:mm:ss) [Returns Array(2) of Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_length_hms(id)
time = get_length_ms(id)
total_seconds = time / 1000
seconds = (total_seconds % 60).truncate
total_minutes = total_seconds / 60
minutes = (total_minutes % 60).truncate
total_hours = total_minutes / 60
hours = (total_hours % 60).truncate
return [hours, minutes, seconds]
end
#-------------------------------------------------------------------------
# Get Audio ID Position (Milliseconds) [Returns Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_pos_ms(id)
pos = " " * 255
@media.call("status sAudio#{id} position", pos, 255, 0)
return pos.to_i
end
#-------------------------------------------------------------------------
# Get Audio ID Position (hh:mm:ss) [Returns Array(2) of Numeric]
# id : Audio ID
#-------------------------------------------------------------------------
def get_pos_hms(id)
pos = get_pos_ms(id)
total_seconds = pos / 1000
seconds = (total_seconds % 60).truncate
total_minutes = total_seconds / 60
minutes = (total_minutes % 60).truncate
total_hours = total_minutes / 60
hours = (total_hours % 60).truncate
return [hours, minutes, seconds]
end
#-------------------------------------------------------------------------
# Get Audio ID Status [Returns String]
# id : Audio ID
#-------------------------------------------------------------------------
def status(id)
status = " " * 5
@media.call("status sAudio#{id} mode", status, 5, 0)
status = (status.unpack("aaaa")).to_s
case status
when 'paus'
status = 'Paused'
when 'play'
status = 'Playing'
when 'seek'
status = 'Seeking'
else
status = 'Stopped'
end
return status
end
#-------------------------------------------------------------------------
end
Happily enough, this does allow me to check when a song has ended, as well as other features such as turning off looping, pausing and resuming songs, etc... Unhappily, it does not appear to support wma or mp3 format. This will not do. Anyway, I was wondering if anybody knows why it does not support wma or mp3, and if it could be fixed.