Serialize object/array into a string

Hi there,

Is there any method to serialize an object/array into a string, an equivalent to PHP’s serialize() or json_encode()?

Any help is much appreciated.

Marcus

You can retrieve the XML for most item/list types by using the GetXMLUTF8() method (returns a string). Should work for playlists, playlist items etc.

Hi Torben

Thank you for your quick reply.

Calling that method returns “Unknown identifier ‘GetXMLUTF8’” for me (when calling it from a notification script). Could you please give me an example of how to use this method?

(Tried it in the most recent mAirList 4.0 beta build on a spare computer.)

Thanks,

Marcus

Was able to find the solution myself. Unfortunately, I’m new to Pascal and the documentation doesn’t offer any examples… so it’s try & error :smiley:

Thanks anyway :slight_smile:

Out of interest, what were you trying to do, and which statement(s) solved your problem?

BFN
Cad

Hi Cad :smiley:

I’m developing a multi-platform application to display parts of the playlist history, upcoming playlist items and the playlist item currently being played as well as the automation status – and possibly other things of interest. That application works as an HTTP server and receives the information from mAirList via a HTTP POST request (via a notification script). An that script is what I was working on… Being able to get everything I need in plain XML certainly makes things easier :smiley:

Once that first part is working I would like to develop a helper application that runs on the same computer as mAirList, acts as a web server, too and received commands from the remote display applications… like… AUTOMATION NEXT. That helper application would then relay the commands to mAirList via Windows messaging (I only have the personal edition, so no REST available for me).

The purpose of all this? When you run a web radio station from home and have computers and home automation displays everywhere, it’s helpful if you can just check the current status and influence the programme from anywhere.

Oh… and what solved it… I didn’t call it as a method the Pascal-way, but tried to access it like a function. Of course that didn’t make sense to mAirList’s script interpreter.

By the way… Is there a way to check if an IPlaylistItem has already been played and is inactive now (only visible in history)??! Trying to find a solution to this, but can’t use the CHM file (Windows 7 doesn’t open it, only have a CHM -> HTML conversion, and that’s painful to search through). Perhaps a TPlaylistItemStatusFlag? But then, what flags are there, and how to access that property of an IPlaylistItem? Questions over questions… Could you help me out with some lines of source code?!

I’m beginning to love mAirList even more. Possibilities are endless, thanks to the powerful scripting language :smiley:

Marcus

In v3, simply check if GetHistoryFlag returns true.

By the way, you can open the CHM file in Windows 7. Just uncheck the “always ask me” checkbox from the “this is a downloaded file” security popup message when you open the file. This is an annoying Internet Explorer security “feature”.

Hi Torben, thanks for that trick regarding the CHM file. I didn’t try that obviously as it doesn’t make sense… yet another IE bug lol

Will try GetHistoryFlag then. The CHM still doesn’t have an index OR a full text search index… So I guess I’d have never stumbled over that without your help. Perhaps there will be a full documentation for the scripting interface in the future? Its scripting engine sets mAirList apart from other automation solutions and I wouldn’t want to miss this particular feature now that I have discovered its potential. I’m sure mAirList script developers would benefit from a better documentation and more examples. Well, if I had any clue I’d volunteer to write it!

Anyway, thanks again for your help. The support here goes beyond my expectations! :slight_smile:

Ok this is how far I got…

procedure OnPlaylistChange(PlaylistIndex: integer);

var
  i, i2, iItemCount, iMax: integer;
  plCurrent: IPlaylist;
  currentItem: IPlaylistItem;
  st: widestring;

begin
  st := '';
  plCurrent := Factory.CreatePlaylist;
  plCurrent.Assign(CurrentPlaylist);
  iItemCount := CurrentPlaylist.GetCount;
  iMax := iItemCount - 1;

  i2 := 0;
  for i := 0 to iMax do
  begin
    currentItem := plCurrent.GetItem(i);
    if currentItem.GetHistoryFlag = false then
    begin
      st := st + currentItem.GetXMLUTF8(ofNone);
      i2 := i2 + 1;
      if i2 > 4 then break;
    end;

  end;

  HTTPPostAsync('http://192.168.178.32:8080/playlist/', st );
end;


begin
end.

I’m now learning the Pascal syntax— so please feel free to point out if anything looks weird. Copy & pasting from Cad’s sources mostly :wink:

The HTTPPostAsync call currently results in a “HTTP call failed: Read Timeout” error; my application acting as an HTTPD receives only a small part of the text string— it is cut off at some point, sometimes already after about 400 chars, sometimes after 2000 chars. The timeout error does not occur when I submit a shorter string, like “ABC123”.
Is it possible for a script to change the timeout interval?

Marcus

I would like to add that the call to plCurrent.GetItem(i) results in an Access Violation in mAirList 4, it runs fine with mAirList 3 (latest built) though.

The scripting code in the current v4 snapshot seems to be broken in a way. I’ll investigate it.

The timeout is hardcoded to 10 seconds, if I remember correctly. Is your server notably slow? Have you tried the synchronous method HTTPPost instead? Same error? Notification scripts run in their own thread anyway, there’s no need to use the asynchronous call (which would start another thread).

Thanks Torben.

Replaced the async call with HTTPPost. Nothing cut off anymore, full string is received. However, now I’m getting this message in the log:

20.06.2011 22:05:49 Error Runtime error “Connection Closed Gracefully.” in notification script C:\Audio\Scripts\test2.mls, handling message: PLAYLIST_CHANGE 09E4D6C9368859F2 0009

Anything wrong?

Indy (the Delphi Internet components) sometimes reports even a good status as an exception. I will try to filter it out.

I haven’t seen this when working with Apache etc. - perhaps your server is doing something wrong when closing the connection? Don’t know.

Hi Torben,

What happened to GetHistoryFlag? I can’t find a reference to it in the CHM file anymore. Did you replace it with another method, or did the name change?

Cheers,
Marcus

(almost off-topic: For those having trouble viewing the CHM help file unter Windows 7: http://www.ec-software.com/products_hhreg.html corrects the problem quickly. Just add the CHM file as an exception and you will be able to browse it!)

Try the Playlist.GetMetadata(index).GetState method. It returns one of the following values:

pisNormal
pisPlaying
pisHistory
pisError

Generally, the new IPlaylistItemMetadata object holds the (temporary) metadata about the item in the given playlist, in particular its playback state and the backtiming information.

The reason for this change is that, in theory (and also in practice), a particular playlist item can be member of more than one playlist at the same time, so the metadata must be instantiated separately for each playlist.

Of course, a single item is never member of to “real” playlists at the same time, but there are temporary playlist objects used when you move the items around, or into the Mix Editor, for example.

Working like a charm. Well, for the time being lol :smiley:

THANKS!

Great.

On a side note, pisError has been eliminated in Build 1210. Items are now either normal (=unplayed), playing, or history (=played). If there’s an error, the pisfError flag will be set in GetStatusFlags.

The reason for this change is that the error flag can both apply to unplayed an played items. For example, it is set when you call the ErrorCheck method on an item or the playlist, and an error is detected on an unplayed item. The item is still in “unplayed” state, and when it is about to be played, mAirList will try again to load it. When it still fails, it will be set to pisHistory.