It is currently Tue Sep 26, 2017 6:21 am


All times are UTC [ DST ]




Post new topic Reply to topic  [ 47 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: Sun Aug 24, 2008 5:46 pm 
User avatar

Joined: Fri Jul 14, 2006 3:48 pm
Posts: 129
Location: Manchester, UK
I've just created an interface using Visual Studio c# 2008 - I am trying to get it to talk to Album player, but I've no idea where to start. I've tried to pick through the demo application and cut-n-paste bits in to my own, but nothing seems to work.

Is there any chance someone can do a simple step by step guide to getting the first basic command working? Once I can talk to AP, I can do the rest probably.

All I want to do is to pause the music while I load another app, then on closing that app (the one I've created) restart it!

Thanks for any info!

_________________
Touchscreen Jukeboxes


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 7:49 am 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
You want to develop with c#?

First thing to do is to send a "subscribe for info" message to the AP. After that it will start sending "now playing" info to you.

If you develop using c#, I advice to copy the AlbumPlayerControl.cs file from the test application to yours. You find the SubscribeForInfo message there. Just call it.

To receive messages add the following method to your Main form.

Code:
        protected override void WndProc(ref Message msg)
        {
            if (msg.Msg == AlbumPlayerControl.WM_USER)
            {
                switch ((int)msg.WParam)
                {
                    case 0:  // new track starts to play
//                        AppendOutput(string.Format("# New track starts to play, length {0} ms", msg.LParam));
                        break;
                    case 4:  // track information of now playing track is updated
//                        AppendOutput(string.Format("# Now playing info update, length {0} ms", msg.LParam));
                        break;
                    case 6:  // track information of now playing track is updated
                        if (!suppressProgressUpdatesCheckBox.Checked)
                            AppendOutput(string.Format("# Track progress, position {0} ms", msg.LParam));
                        break;
                    case 10:  // playlist is changed
                        AppendOutput("# Playlist is changed");
                        break;
                    case 1:  // play state changed
                        {
                            switch ((int)msg.LParam)
                            {
                                case 0: // stopped
                                    AppendOutput("# Play state is changed, stopped");
                                    break;
                                case 1: // playing
                                    AppendOutput("# Play state is changed, playing");
                                    break;
                                case 2: // paused
                                    AppendOutput("# Play state is changed, paused");
                                    break;
                            }
                        }
                        break;
                    case 12:  // new track starts to play
                        AppendOutput(string.Format("# Volume set to {0}", msg.LParam));
                        break;
                }
                msg.Result = (IntPtr)1;
            }
            else if (msg.Msg == AlbumPlayerData.WM_COPYDATA)
            {
                AlbumPlayerData.COPYDATASTRUCT cds = new AlbumPlayerData.COPYDATASTRUCT();
                cds = (AlbumPlayerData.COPYDATASTRUCT)Marshal.PtrToStructure(msg.LParam, typeof(AlbumPlayerData.COPYDATASTRUCT));
                if (cds.cbData > 0)
                {
                    byte[] data = new byte[cds.cbData];
                    Marshal.Copy(cds.lpData, data, 0, cds.cbData);
                    MemoryStream stream = new MemoryStream(data);

                    // show the command
                    AppendOutput(stream);

                    HandleXmlReply(stream);

                    msg.Result = (IntPtr)1;
                }
            }
            else
            {
                base.WndProc(ref msg);
            }
        }



The AppendOutput function just shows the received information in a text field of the test application. So you can replace this for everything you like.

To read received XML message with now playing info you can use the following method:

Code:
        private void HandleXmlReply(MemoryStream stream)
        {
            // interpret the command
            XmlTextReader xmlReader = new XmlTextReader(stream);
            xmlReader.Read();
            if (xmlReader.ReadToFollowing("AlbumPlayerReply"))
            {
                switch (xmlReader.GetAttribute("id"))
                {
                    case "GetNowPlayingInfo":

                        while (xmlReader.Read())
                        {
                            if (xmlReader.NodeType == XmlNodeType.Element)
                            {
                                if (xmlReader.LocalName == "Album")
                                {
                                    Album album = new Album();
                                    album.ReadFromXml(xmlReader);

                                    // write code here to do something with the album info

                                }
                                else if (xmlReader.LocalName == "Track")
                                {
                                    Track track = new Track();
                                    track.ReadFromXml(xmlReader);

                                    // write code here to do something with the track info
                                }
                            }
                            else if (xmlReader.NodeType == XmlNodeType.EndElement) // AlbumPlayerReply closing tag
                            {
                                return;
                            }
                        }
                        break;
                }
            }
        }


In this piece of code the classes Album and Track are used. The XML message is read and the info is put into these classes. You can add these ones to your project by copying the Album.cs and Track.cs files to your project.

I hope this info helps a bit


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 11:56 am 
User avatar

Joined: Fri Jul 14, 2006 3:48 pm
Posts: 129
Location: Manchester, UK
thanks Peter, I've pasted that code in and copied AlbumplayerControl.cs to my project, but I get a lot of errors, such as

"The name AlbumPlayerControl does not exist in the current context"

there are various others too.. I assume this is because I am not referencing the CS file? (I'm new to this!!)

It is c# I am using :)

_________________
Touchscreen Jukeboxes


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 12:03 pm 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
You first have to copy the file and then add it to your project. But I think you also have to adjust the namespace. It is on the top of the file. Make the namespace the same as the other files in your project.

If you do not succeed, I will make a small project only containing the most essential files as soon as I find the time for it.


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 12:14 pm 
User avatar

Joined: Fri Jul 14, 2006 3:48 pm
Posts: 129
Location: Manchester, UK
thanks - I changed the namespace to "matts_test_1" but still get the error messages.

All I need to do is to control album player to PAUSE and PLAY (unpause?) the track. If you have time to put together a project, that would be awesome!!

_________________
Touchscreen Jukeboxes


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 12:21 pm 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
Which Visual Studio do you use? 2003, 2005 or 2008


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 1:34 pm 
User avatar

Joined: Fri Jul 14, 2006 3:48 pm
Posts: 129
Location: Manchester, UK
Visual C# 2008 Express Edition :)

_________________
Touchscreen Jukeboxes


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 1:41 pm 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
Ok, then I create a 2008 project. I will see if I can do something this week.


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 1:53 pm 
User avatar

Joined: Fri Jul 14, 2006 3:48 pm
Posts: 129
Location: Manchester, UK
brilliant, thanks!!

_________________
Touchscreen Jukeboxes


Top
Offline Profile  
 
 Post subject:
PostPosted: Mon Jan 16, 2012 6:19 pm 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
The Documentation is update to V5.3 . See main post.


Top
Offline Profile  
 
 Post subject: Re: AlbumPlayer interface for Add-ons
PostPosted: Sat Mar 14, 2015 11:59 am 

Joined: Sat Mar 14, 2015 11:34 am
Posts: 4
From the interface doc:
Code:
4.8 Notifications
This message is send spontaneous when state change in AP

4.8.1 Notification
Reply

<AlbumPlayerReply id="Notification">
  <PlayState>Stopped</PlayState>
  <Position>23.5</Position>
  <Volume></Volume>
  <Playlist>Top 500</Playlist>
  <Settings>PreferencesChanged</Settings>
  <Grid>PageChanged</Grid>
</AlbumPlayerReply>


There is the reply, but how is the command to get those spontaneous messages? I know there is WM_SUBSCRIBE_FOR_NOTIFICATIONS for the simple message interface, but how to subscribe for notifications in the XML message interface?


Top
Offline Profile  
 
 Post subject: Re: AlbumPlayer interface for Add-ons
PostPosted: Mon Mar 16, 2015 1:22 pm 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
You have to use WM_COPY_DATA to get the XML messages


Top
Offline Profile  
 
 Post subject: Re: AlbumPlayer interface for Add-ons
PostPosted: Tue Mar 17, 2015 8:48 pm 

Joined: Sat Mar 14, 2015 11:34 am
Posts: 4
Sorry if i have to ask again. I'm new to this window message stuff. :oops:
If i understand correct, with the xml interface i have to send a request via WM_COPY_DATA and get a reply. So, what is the request to get those notifications per xml?


Top
Offline Profile  
 
 Post subject: Re: AlbumPlayer interface for Add-ons
PostPosted: Wed Mar 18, 2015 10:26 am 
AlbumPlayer Developer
User avatar

Joined: Wed Feb 26, 2003 5:09 pm
Posts: 4754
If you use C# then just look into this example http://www.albumon.com/attachments/AP_InterfaceTest.zip

And even when not using c# that might be helpful


Top
Offline Profile  
 
 Post subject: Re: AlbumPlayer interface for Add-ons
PostPosted: Thu Mar 19, 2015 6:33 pm 

Joined: Sat Mar 14, 2015 11:34 am
Posts: 4
The AP interface test help for the most things, except for what i'm asking here. I don't get a xml message with the id "Notification". I don't know C# so maybe i didn't saw the relevant code snippet. (I use Python for progamming and i'm still a beginner.)


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Moderators: Jan, xblkx, Peter van der Burg Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net