[SOLVED] How to create a song object?

Post a reply

:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review

Expand view Topic review: [SOLVED] How to create a song object?

Re: [SOLVED] How to create a song object?

by Peke » Thu May 02, 2019 3:19 pm

I would use this approach instead of your example as it will not keep playlist file open

Code: Select all

Set obj = CreateObject(“Scripting.FileSystemObject”)    ‘Creating a File Object
Const ForReading = 1                      ‘Defining Constant Value to read from a file
Set obj1 = obj.OpenTextFile(“C:\app.txt”, ForReading) ‘Opening a text file and reading text from it
Dim str,str1
str=obj1.ReadAll                                              ‘All text from the file is read using ReadAll
Dim strLines() As String = Split(Replace(str,Chr(13),""),Chr(10)) ‘Split lines in Array and it works in linux based M3Us
Msgbox str                                ‘Contents of a file will be displayed through message box
Do while obj1.AtEndofStream                  ‘Reading text line wise using Do Loop and ReadLine
Msgbox str1
obj1.Close                                         ‘Closing a File
Set obj=Nothing                              ‘Releasing File object

Re: [SOLVED] How to create a song object?

by marceros » Thu May 02, 2019 8:05 am

I managed to create the SongData object but the program behaves strange. I'm attaching the code that does the following:
1. reads lines (from a M3U file) with paths to MP3 music files
2. creates a new song object
3. connects the song object with the path
4. runs the ReadRags method
5. adds the song object to a playlist (created previously in the code)

The first round of the loop works good but in the second round, the song object gets stuck with the same first music so I end up with only one music in the playlist.

Code: Select all

System.IO.StreamReader reader = new System.IO.StreamReader(playlistDisk_path);
while (!reader.EndOfStream)
    string line = reader.ReadLine();
    if (line[0] != '#')
         SongsDB.SDBSongData song = new SongsDB.SDBSongData();

Re: How to create a song object?

by Peke » Wed May 01, 2019 5:59 pm

My pleasure always. I also noted that AddByID is missing in SDBSongList for some future MM versions ;)

Re: How to create a song object?

by marceros » Wed May 01, 2019 5:23 am

Thank you very much, Pavle!

I write in C# but after your response I realized that I was doing a mistake in my coding and it seems to work now. I'll finish writing the whole procedure and I'll check again.


Re: How to create a song object?

by Peke » Tue Apr 30, 2019 7:44 pm

Try this

Code: Select all

Dim NewSong
Set NewSong = CreateObject("SDB.SDBSongData")
NewSong.Path = "C:\Temp\Test.mp3"
Set NewSong = Nothing
You could also want to first query for path in Library

Code: Select all

Dim NewSong, TrackID.
Set TrackID = -1
Set NewSong = CreateObject("SDB.SDBSongData")

Set Iter = SDB.Database.QuerySongs("Path = 'C:\Temp\Test.mp3'")
While Not Iter.EOF
  TrackID = Iter.Item.SongID
Set Iter = Nothing ' Avoid locking errors
Now you can either Manipulate Track ID and Directly Insert https://www.mediamonkey.com/wiki/index. ... st_members track to playlist or use https://www.mediamonkey.com/wiki/index. ... DBSongList to fill info and then https://www.mediamonkey.com/wiki/index. ... :AddTracks to fill MM playlist.

I hope I helped with this brief explanation it would be much simpler if https://www.mediamonkey.com/wiki/index. ... DBSongList supported AddByID like SDBPlaylist but it is missing :(

[SOLVED] How to create a song object?

by marceros » Tue Apr 30, 2019 5:16 pm


I have to import a song to a playlist. The song may or may not be in the database (it's very likely that it IS in the database) but I have the path of the MP3 file in the disk.

I assume I want to use the SDBSongData object but how to create a new object when I only have the path string?

Thank you in advance,