Page 1 of 4

Back Button 1.0 [MM2]

Posted: Wed Mar 01, 2006 4:06 am
by trixmoto
This script remembers previously played tracks so you can skip back even when in shuffle mode.

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

Posted: Wed Mar 01, 2006 5:43 am
by onkel_enno
Why don't you only look at Table "Played" which Song was played last (or Table "Songs" Field "LastTimePlayed")? :wink:

Posted: Wed Mar 01, 2006 5:52 am
by trixmoto
You could use the database but I couldn't remember how they were updated. I thought they weren't updated until you were a third of the way through the track or something. Or is that just the playcounter?

Posted: Wed Mar 01, 2006 6:51 am
by onkel_enno
I don't know, but if you're right then your way might be better.

Posted: Wed Mar 01, 2006 8:20 am
by psyXonova
trixmoto wrote:You could use the database but I couldn't remember how they were updated. I thought they weren't updated until you were a third of the way through the track or something. Or is that just the playcounter?
Trix is right, the 1/3 of the song must be played to be entered in the "Played" table

Posted: Thu Apr 20, 2006 11:03 am
by Guest
@trixmoto:
Real nice plugin, thanks for it. It is how the Back Button should behave... :roll:

By the way, is there a way to change the "back button" behavior so that it behaves as this plugin?

Posted: Thu Apr 20, 2006 3:23 pm
by trixmoto
No this is not possible. By the devs have said they'll look into the behaviour, so it might be fixed in a future version.

Posted: Fri Apr 21, 2006 3:13 am
by Guest
:D Great!!!

Thanks for the info and -- once again -- for the plugin. :wink:

Posted: Fri Apr 21, 2006 3:14 am
by Guest
Anonymous wrote:(...) for the plugin (...)
err... I mean for the script. :roll:

Posted: Sun Jul 02, 2006 4:50 am
by trixmoto
Zachm019 wrote:WOW Thanks a TON trixmoto!!! Do you happen to know if there is a way to create a short cut for that script? I got it installed and working just wondering if there was a way I could press a key combination for it to work... now on the sad note while I was typing it this message it went forward to another song and I got two error messages...

Image
Image

Do you know what is causing this?
Originally posted here: http://www.mediamonkey.com/forum/viewto ... 2448#52448

Posted: Sun Jul 02, 2006 4:59 am
by trixmoto
In the "{MM}\Scripts\Scripts.ini" file you will find the following entries...

Code: Select all

[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
That blank line might not be there, but it is in this space (directly before "[BackButton2]") that you will want to add the following line...

Code: Select all

Shortcut=Ctrl+Shift+B
Or whatever shortcut key combination you want!

About the error: There is a variable at the top of the BackButton.vbs file called "Capacity" which by default is 10. Have you changed this? If so, what to?

If you could open "{MM}\MediaMonkey.ini" in a text editor and find the [Scripts] secction and tell me the value of "BackButtonMemory" - that might also be useful.

Posted: Sun Jul 02, 2006 2:18 pm
by Zachm019
I have recopied your code as said... in the script.ini and the BackButton.vbs. Without changing anything but adding the shortcut information in the blank line and I still get the error message

Posted: Sun Jul 02, 2006 5:14 pm
by trixmoto
Could you please open "{MM}\MediaMonkey.ini" in a text editor and find the [Scripts] secction and tell me the value of "BackButtonMemory" - this is probably the root of the problem.

Posted: Sun Jul 02, 2006 5:26 pm
by Zachm019
in the mediamonkey.ini this is all that is there

[out_ds]
cfg_total_time=36539093

Posted: Sun Jul 02, 2006 5:59 pm
by trixmoto
Then you're looking at the wrong .ini file. Try the one in "..\My Documents\My Music\MediaMonkey\".