I solved the JSON problem with a code snippet I found (MiniJSON). Actually I am almost done and I am surprised how it turned out to be. The script finds duplicate files of all files in playing now, suggests to keep the best one (user can select), merges the playlists the duplicate files are in, presents a user dialog to edit the artist, album, track, playlists, etc., it is possible to get track info from two online databases (Discogs and AllMusic), then it moves the file to the final folder, and also a cover image is downloaded.
As soon as it has all the bells and whistles on it I will post it here.
However, I come across another problem I cannot solve. While editing the track info in a dialog, I start playback of that song. After editing, the song is stopped, and the next track is played while editing. But after about 5 mins I always get a runtime error (see at end). Below is the relevant code I use to handle the playback. Can you help me and tell me what I am doing wrong?
class Script : MarshalByRefObject {
PlayBack playback; // see PlayBack class below
MediaCenter.IMJCurPlaylistAutomation fpl; // will hold the Playing Now playlist of the main zone (Player)
public void Init(MediaCenter.MCAutomation mediaCenterInterface) {
fpl = mediaCenterInterface.GetZones().GetZone(0).GetCurPlaylist();
playback = new PlayBack(ref mediaCenterInterface, fpl); // does not make a difference if I use 'ref' or not
...
// playback is started and stopped in the Init method
...
}
...
private function () {
// there are also some functions where playback is started and stopped
}
...
}
public class PlayBack {
private MediaCenter.MCAutomation mca;
private MediaCenter.IMJCurPlaylistAutomation cpla;
private bool songplaying = false; // In order to play a song with the script, it must be added to the playing now list (first file), this var holds the information, if a song was added or not (for correct removal)
public PlayBack (ref MediaCenter.MCAutomation mcao, MediaCenter.IMJCurPlaylistAutomation cplao) {
mca = mcao;
cpla = cplao;
}
public bool play(int key, int startpos) {
try {
if (songplaying) stop();
cpla.AddFileByKey(key, 0);
cpla.Position = 0;
MediaCenter.IMJPlaybackAutomation play = mca.GetPlayback();
play.Play();
play.Position = startpos;
if (play.State!=MediaCenter.MJPlaybackStates.PLAYSTATE_STOPPED) songplaying = true;
}
catch (Exception _Exception) {
Console.WriteLine("Exception caught in call PlayBack method play: {0}", _Exception.ToString());
return false;
}
return songplaying;
}
public void stop() {
try {
if (!songplaying) return;
MediaCenter.IMJPlaybackAutomation play = mca.GetPlayback();
play.Stop();
cpla.RemoveFile(0);
songplaying = false;
}
catch (Exception _Exception) {
Console.WriteLine("Exception caught in call PlayBack method stop: {0}", _Exception.ToString());
}
}
}
Exception caught in call PlayBack method stop: System.Runtime.Remoting.RemotingException: The object "/6993d6c8_ee6b_4f98_8fe4_e11b55ca8838/rgndhpe+duq0elupmsdmadot_7.rem" was disconnected or is not present on the server.
Server stack trace:
bei System.Runtime.Remoting.Channels.ChannelServices.CheckDisconnectedOrCreateWellKnownObject(IMessage msg)
bei System.Runtime.Remoting.Channels.ChannelServices.SyncDispatchMessage(IMessage msg)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
bei MediaCenter.IMJAutomation.GetPlayback()
bei PlayBack.stop() in c:\Program Files (x86)\J River\Media Center 18\Plugins\Script Plugin\Scripts\CleanDuplicates.cs:Zeile 1916.
Exception caught in call PlayBack method stop: System.Runtime.Remoting.RemotingException: The object "/6993d6c8_ee6b_4f98_8fe4_e11b55ca8838/rgndhpe+duq0elupmsdmadot_7.rem" was disconnected or is not present on the server.
Server stack trace:
bei System.Runtime.Remoting.Channels.ChannelServices.CheckDisconnectedOrCreateWellKnownObject(IMessage msg)
bei System.Runtime.Remoting.Channels.ChannelServices.SyncDispatchMessage(IMessage msg)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
bei MediaCenter.IMJAutomation.GetPlayback()
bei PlayBack.stop() in c:\Program Files (x86)\J River\Media Center 18\Plugins\Script Plugin\Scripts\CleanDuplicates.cs:Zeile 1916.
Failure Running Script :-
Ein Aufrufziel hat einen Ausnahmefehler verursacht.
The Failure Occured
In Class Object mscorlib
when calling Method System.Object _InvokeMethodFast(System.Object, System.Object[], System.SignatureStruct ByRef, System.Reflection.MethodAttributes, System.RuntimeTypeHandle)
The following Inner Exception was causedSystem.Runtime.Remoting.RemotingException: The object "/6993d6c8_ee6b_4f98_8fe4_e11b55ca8838/gwkczvjtd4ufsaevlk+rev4e_10.rem" was disconnected or is not present on the server.
Server stack trace:
bei System.Runtime.Remoting.Channels.ChannelServices.CheckDisconnectedOrCreateWellKnownObject(IMessage msg)
bei System.Runtime.Remoting.Channels.ChannelServices.SyncDispatchMessage(IMessage msg)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
bei MediaCenter.IMJCurPlaylistAutomation.GetFile(Int32 nFile)
bei Script.Init(MCAutomation mediaCenterInterface) in c:\Program Files (x86)\J River\Media Center 18\Plugins\Script Plugin\Scripts\CleanDuplicates.cs:Zeile 250.
Everything that follows forms the stack Trace:
Server stack trace:
bei System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
bei System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
bei System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
bei CSScriptLibrary.AsmBrowser.Invoke(Object obj, String methodName, Object[] list)
bei CSScriptLibrary.AsmRemoteBrowser.Invoke(Object obj, String methodName, Object[] list)
bei System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
bei System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
bei CSScriptLibrary.IAsmBrowser.Invoke(Object obj, String methodName, Object[] list)
bei CSScriptLibrary.AsmHelper.InvokeInst(Object obj, String methodName, Object[] list)
bei ScriptRunner.ScriptRunner.Main(String[] args)