3.0.1.1127 --- problems with reading/writing ini
Posted: Fri Jan 04, 2008 12:10 pm
Ok I've been trying to figure out a problem with tweak monkey script regarding the 'fastnploading' option where it supposed to save the now playing list to the library and restore it upon restart.
in the mediamonkey.ini options are:
using the below code, when startup, change now playing position, then shut down, the now playing positions do not save properly.
At startup, the now playing position should be @ track 11 as expected.
change track position to track 5 then shut down MM3, results in the following mediamonkey.in settings:
I am not able to consistently get the NPCurrentSong and NowPlayingPosition to save properly. Sometimes the NPCurrentSong will be correct, most times the NowPlayingPosition will be correct and NPCurrentSong Incorrect.
Changing the current track and restarting many different times I even get various read memory errors or other crashes from where I have to end the mediamonkey.exe process from the task manager.
Now I did not write all the helper functions for the ini stuff, I am not sure there is a problem with the script code or with the way MM is writing the ini files, but I can't seem to get this working properly.
in the mediamonkey.ini options are:
Code: Select all
[TweakMonkey]
ClearNowPlayingOnExit=False
UseFastNPLoading=True
NPCurrentSong=10
[Player]
NowPlayingPosition=10
using the below code, when startup, change now playing position, then shut down, the now playing positions do not save properly.
Code: Select all
Option Explicit
'note this is a small subset of the full script to help narrow down the problem
Const ScriptName = "TweakMonkey" ' Script Name
Const Version = "1.02" ' Version
Const LastUpdated = "2006-04-02" ' Last updated
Const PlayNow = "Play in MediaMonkey"
Const PlayNext = "Play next in MediaMonkey"
Const PlayLast = "Play last in MediaMonkey"
Dim Tree : Set Tree = SDB.MainTree
Dim INI : Set INI = SDB.IniFile
Dim UI : Set UI = SDB.UI
' ******************************************************************************************************
' EVENT OnShutdown
' **********************************
Sub SDB_OnShutDown
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
SetINIString "PlaybackPosition", SDB.Player.PlayBackTime
SetINIString "PlaybackState", SDB.Player.IsPlaying & "-" & SDB.Player.IsPaused
SetINIString "NPCurrentSong", SDB.Player.CurrentSongIndex
If DoesPlaylistExist("NPSaved") Then SDB.PlaylistByTitle("NPSaved").Delete
If SDB.Player.PlaylistCount > 0 Then
If GetINIBool("UseFastNPLoading", False) Then
Dim RootPlaylist : Set RootPlaylist = SDB.PlaylistByTitle("")
Dim NPSaved : Set NPSaved = RootPlaylist.CreateChildPlaylist("NPSaved")
NPSaved.Clear
Dim CSL : Set CSL = SDB.Player.CurrentSongList
Dim i
For i = 0 To CSL.Count - 1 ' NPSaved.AddTracks CSL seems to be broken
NPSaved.AddTrack(CSL.Item(i))
Next
' SDB.Player.PlaylistClear
End If
End If
If GetINIBool("ClearNowPlayingOnExit", False) Then
SDB.Player.PlaylistClear
End If
End Sub
' **********************************
' EVENT OnStartup
' **********************************
Sub OnStartup
Do While Not SDB.IsRunning
SDB.ProcessMessages
Loop
Script.RegisterEvent SDB, "OnShutDown", "SDB_OnShutDown"
If GetINIBool("UseFastNPLoading", False) Then
If DoesPlaylistExist("NPSaved") Then
If GetINIBool("AutoRandomize", False) Then
RandomizePlayList SDB.PlaylistByTitle("NPSaved")
End If
SDB.Player.PlaylistClear ' To make sure that the playlist is really empty
SDB.Player.PlaylistAddTracks(SDB.PlaylistByTitle("NPSaved").Tracks)
SDB.Player.CurrentSongIndex = (GetINIString("NPCurrentSong", 0))
' SDB.Player.CurrentSongIndex = CLng(GetINIString("NPCurrentSong", 0))
End If
Else
If GetINIBool("LoadPlaylist", False) Then
Dim PlaylistName : PlaylistName = GetINIString("Playlist", "")
If PlaylistName <> "" Then
If DoesPlaylistExist(PlaylistName) Then
SDB.Player.PlaylistClear
SDB.Player.PlaylistAddTracks(SDB.PlaylistByTitle(PlaylistName).Tracks)
End If
End If
End If
If GetINIBool("AutoRandomize", False) Then
RandomizeNowPlaying
End If
End If
End Sub
' ******************************************************************************************************
' HELPER METHODS
' **********************************
Function DoesPlaylistExist(PlaylistName)
DoesPlaylistExist = (SDB.PlaylistByTitle(PlaylistName).Id <> 0)
End Function
Sub RandomizePlayList(Playlist)
Randomize
Dim Songlist : Set Songlist = Playlist.Tracks
Dim n : n = SongList.Count
Dim i
For i = 0 To n - 1
Playlist.MoveTrack Songlist.Item(i), Songlist.Item(Int(n * Rnd))
Next
End Sub
Sub RandomizeNowPlaying
Randomize
Dim n : n = SDB.Player.PlaylistCount
Dim i
For i = 0 To n - 1
SDB.Player.PlaylistMoveTrack i, Int(n * Rnd)
Next
End Sub
'%%%%%%%%%%%%%%%
' INI PROPS
'%%%%%%%%%%%%%%%
Function GetINIBool(pName, pValueIfMissing)
If pValueIfMissing Then
If SDB.IniFile.StringValue(ScriptName, pName) = "False" Then
GetINIBool = False
Else
GetINIBool = True
End If
Else
If SDB.IniFile.StringValue(ScriptName, pName) = "True" Then
GetINIBool = True
Else
GetINIBool = False
End If
End If
End Function
Function GetINIString(pName, pValueIfMissing)
GetINIString = SDB.IniFile.StringValue(ScriptName, pName)
If GetINIString = "" Then
GetINIString = pValueIfMissing
End If
End Function
Sub SetINIString(pName, pValue)
SDB.IniFile.StringValue(ScriptName, pName) = pValue
End Sub
Sub SaveCheckValue(Sheet, CheckName)
SetINIString CheckName, Sheet.Common.ChildControl(CheckName).Checked
End Sub
Sub SaveTextValue(Sheet, CheckName)
SetINIString CheckName, Sheet.Common.ChildControl(CheckName).Text
End Sub
'%%%%%%%%%%%%%%%
' MEDIAMONKEY
'%%%%%%%%%%%%%%%
Function GetINIPath()
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
GetINIPath = SDB.MyMusicPath & "MediaMonkey\MediaMonkey.ini"
If FSO.FileExists(GetINIPath) Then Exit Function
GetINIPath = SDB.ApplicationPath & "MediaMonkey.ini"
If FSO.FileExists(GetINIPath) Then Exit Function
GetINIPath = ""
End Function
Function GetINILocation()
Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(SDB.MyMusicPath & "MediaMonkey\MediaMonkey.ini") Then
GetINILocation = 1
ElseIf FSO.FileExists(SDB.ApplicationPath & "MediaMonkey.ini") Then
GetINILocation = 2
Else
GetINILocation = 0
End If
End Function
Function GetDBPath()
GetDBPath = SDB.Database.Path
End Function
change track position to track 5 then shut down MM3, results in the following mediamonkey.in settings:
Code: Select all
NPCurrentSong=10
and
NowPlayingPosition=4Changing the current track and restarting many different times I even get various read memory errors or other crashes from where I have to end the mediamonkey.exe process from the task manager.
Now I did not write all the helper functions for the ini stuff, I am not sure there is a problem with the script code or with the way MM is writing the ini files, but I can't seem to get this working properly.