Code: Select all
'
' MediaMonkey Script
'
' NAME: BackButton 1.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 28/02/2006
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
' Set the Capacity variable to the value you require
'
' [BackButton]
' FileName=BackButton.vbs
' ProcName=BackButton
' Order=31
' DisplayName=Back Button
' Description=Back Button
' Language=VBScript
' ScriptType=0
' [BackButton2]
' FileName=BackButton.vbs
' ProcName=BackButton2
' Order=31
' DisplayName=Back Button 2
' Description=Back Button 2
' Language=VBScript
' ScriptType=2
'
Option Explicit
Dim Capacity
Capacity = 10 ' number of tracks to remember
Sub BackButton
'check there is a memory
Dim str,pos
str = SDB.IniFile.StringValue("Scripts","BackButtonMemory")
If str = "" Then
pos = SDB.MessageBox("Sorry, there are no tracks in the memory to go back to.",mtInformation,Array(mbOk))
Exit Sub
End If
'check memory contains current track
str = Left(str,Len(str)-1)
pos = InStrRev(str,"|")
If pos < 2 Then
pos = SDB.MessageBox("Sorry, there are no tracks in the memory to go back to.",mtInformation,Array(mbOk))
Exit Sub
End If
'check memory contains previous track
str = Left(str,pos-1)
pos = InStrRev(str,"|")
If pos = 0 Then
pos = SDB.MessageBox("Sorry, there are no tracks in the memory to go back to.",mtInformation,Array(mbOk))
Exit Sub
End If
'extract previous track from memory
Dim trk
trk = Int(Mid(str,pos+1))
str = Left(str,pos)
'find last track
Dim found
found = False
If SDB.Player.CurrentSong.ID = trk Then
'play if currently now playing
found = True
Else
'play if in now playing list
Dim list,itm,i
Set list = SDB.Player.CurrentSongList
For i = 0 To list.Count-1
Set itm = list.Item(i)
If itm.ID = trk Then
SDB.Player.CurrentSongIndex = CLng(i)
found = True
Exit For
End If
Next
'else add to now playing
If not found Then
Dim sql,iter
sql = "AND (Songs.ID="&trk&")"
Set iter = SDB.Database.QuerySongs(sql)
If Not iter.EOF Then
SDB.Player.PlaylistAddTrack(iter.Item)
SDB.Player.CurrentSongIndex = list.Count
found = True
End If
End If
End If
'play and update memory
If found Then
SDB.IniFile.StringValue("Scripts","BackButtonMemory") = str
Else
pos = SDB.MessageBox("Sorry, the previous track could not be found.",mtInformation,Array(mbOk))
End If
End Sub
Sub BackButton2
'add track to memory
Dim str,arr,trk,max,tmp
trk = SDB.Player.CurrentSong.ID
str = SDB.IniFile.StringValue("Scripts","BackButtonMemory")
If str = "" Then
str = "|"&trk&"|"
Else
tmp = str
str = str&trk
arr = Split(Mid(str,2),"|")
max = UBound(arr)
If arr(max-1) = arr(max) Then
str = tmp
Else
If max >= Capacity Then
str = Mid(str,InStr(2,str,"|"))
End If
str = str&"|"
End If
End If
SDB.IniFile.StringValue("Scripts","BackButtonMemory") = str
End Sub