Trying to use https://github.com/japlscript/obstmusic to talk to Apple Music app on macOS with Java, I used to write native AppleScript and then java applescript library but that was removed from Java.
In this method it looks for a existing folder playlist called songkong, it it finds it then returns it. If none exists then it creates such a folder and then returns it.
private FolderPlaylist getPlayListFolder()
{
Application app = Application.getInstance();
com.tagtraum.macos.music.Playlist[] songKongPlaylists = app.getPlaylists();
for(com.tagtraum.macos.music.Playlist next:songKongPlaylists)
{
if(next.getName().equals("songkong"))
{
return (com.tagtraum.macos.music.FolderPlaylist)next;
}
}
Object songkongPlaylist = app.make(FolderPlaylist.class);
if(songkongPlaylist instanceof FolderPlaylist)
{
((FolderPlaylist)songkongPlaylist).setName("songkong");
return ((FolderPlaylist)songkongPlaylist);
}
return null;
}
First time I run it when I have to create a folder playlist, because non exists it works, but if I run again so it finds an existing folder playlist it then fails complaining as follows
4/04/2022 14.53.25:BST:OSXUpdateItunesWithChanges:updateItunes:SEVERE: *** Unable to run itunes update:class jdk.proxy2.$Proxy62 cannot be cast to class com.tagtraum.macos.music.FolderPlaylist (jdk.proxy2.$Proxy62 is in module jdk.proxy2 of loader 'app'; com.tagtraum.macos.music.FolderPlaylist is in unnamed module of loader 'app') java.lang.ClassCastException: class jdk.proxy2.$Proxy62 cannot be cast to class com.tagtraum.macos.music.FolderPlaylist (jdk.proxy2.$Proxy62 is in module jdk.proxy2 of loader 'app'; com.tagtraum.macos.music.FolderPlaylist is in unnamed module of loader 'app') at com.jthink.songkong.ituneshelper.OSXUpdateMusicWithChanges.getPlayListFolder(OSXUpdateMusicWithChanges.java:41) at com.jthink.songkong.ituneshelper.OSXUpdateMusicWithChanges.createPlaylist(OSXUpdateMusicWithChanges.java:56) at com.jthink.songkong.ituneshelper.OSXUpdateItunesWithChanges.analyseFiles(OSXUpdateItunesWithChanges.java:246) at com.jthink.songkong.ituneshelper.OSXUpdateItunesWithChanges.updateItunes(OSXUpdateItunesWithChanges.java:126) at com.jthink.songkong.ituneshelper.UpdateItunesWithChanges.call(UpdateItunesWithChanges.java:184) at com.jthink.songkong.ituneshelper.UpdateItunesWithChanges.call(UpdateItunesWithChanges.java:33) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
Im not using modules so I think references to modules is probably misleading. More likely the issue I have to do something more than just cast from Playlist to FolderPlaylist but I cannot find an alternative.