Detect if XBMC plays video

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
phanos Offline
Junior Member
Posts: 34
Joined: Feb 2011
Reputation: 0
Post: #1
Hi,

I am developing a utility that will enter my computer in stand by when :

1) no other client is connected to it (this is the main pvr HTPC), and
2) when XBMC does not play video. I am developing the utility in c#.


So far I was successful implementing part 1 (when no clients are connected on the main pvr HTPC) but I am having problems detecting when XBMC plays video.

Is there a way to detect when XBMC is playing video?

Thanks

Phanos
find quote
Montellese Online
Team-XBMC Developer
Posts: 2,834
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #2
You can use JSON-RPC's Player.GetActivePlayers method.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
(This post was last modified: 2013-04-14 22:02 by Montellese.)
find quote
phanos Offline
Junior Member
Posts: 34
Joined: Feb 2011
Reputation: 0
Post: #3
I tried to use the recommendation for JSON-RPC. Through my browser it works fine (http://127.0.0.1:8080/jsonrpc) but through c# code I get

{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

My code works fine when I try to use it for POST on other web servers.

Does anybody have a clue about what the problem here?

My code is the following

Code:
String uri = "http://127.0.0.1:8080/jsonrpc";
            try
            {
                // create a request
                HttpWebRequest request = (HttpWebRequest)
                WebRequest.Create(uri); request.KeepAlive = false;
                request.ProtocolVersion = HttpVersion.Version10;
                request.Method = "POST";

                // turn our request string into a byte stream
                byte[] postBytes = Encoding.ASCII.GetBytes(uri);

                // this is important - make sure you specify type this way
                request.ContentType = "application/json";
                request.ContentLength = postBytes.Length;
                Stream requestStream = request.GetRequestStream();

                // now send it
                requestStream.Write(postBytes, 0, postBytes.Length);
                requestStream.Close();

                // grab te response and print it out to the console along with the status code
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                returnresults = (new StreamReader(response.GetResponseStream()).ReadToEnd()).ToString();
                MessageBox.Show(returnresults, "Results");
                StreamWriter t = File.AppendText("out.txt");
                t.Write(returnresults);
                t.Close();
                MessageBox.Show(response.StatusCode.ToString(), "Results");
                //Console.WriteLine(returnresults);
                //Console.WriteLine(response.StatusCode);
            }
            catch (Exception ex)
            {
                LogEntry("Log.txt", ex.Message);
                MessageBox.Show(ex.Message, "Error");
            }
(This post was last modified: 2013-04-15 13:52 by phanos.)
find quote
Tolriq Online
Member+
Posts: 1,875
Joined: Jun 2009
Reputation: 53
Location: France
Post: #4
We don't see the request in this but byte[] postBytes = Encoding.ASCII.GetBytes(uri); is a potential problem all should be UTF 8 in and out Smile

Yatse 2 : Media Center Remote Control for Touch Screens
Yatse, the Xbmc Remote and Widgets for Android
find quote
phanos Offline
Junior Member
Posts: 34
Joined: Feb 2011
Reputation: 0
Post: #5
I tried UTF8 in my code but the result is the same byte[] postBytes = Encoding.UTF8.GetBytes(uri). Do I have to change it somewhere in XBMC as well?
find quote