AirPlay target support integrated into XBMC natively?

  Thread Rating:
  • 3 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Closed
logictester Offline
Fan
Posts: 673
Joined: Oct 2008
Reputation: 0
Location: USA
Post: #31
vinc Wrote:http://www.youtube.com/watch?v=2oBfC8Lqumo

Looks SWEET!!!
find
vinc Offline
Junior Member
Posts: 14
Joined: Dec 2010
Reputation: 0
Post: #32
asked for an ETA via Twitter, he said he'll be releasing an alpha version this week.
find
Blieb Offline
Junior Member
Posts: 13
Joined: Dec 2010
Reputation: 0
Post: #33
It's not that hard, I just played with php and make this possible:
http://www.twitvid.com/ORKK0

I tested it only with youtube (why does it not work for the other one?). That works great, but alot problems, can't wait for the alpha Tongue

oh and also the picture vieuwer works, but I don't know how I can let xbmc show a picture via json-rpc Tongue
find
vinc Offline
Junior Member
Posts: 14
Joined: Dec 2010
Reputation: 0
Post: #34
@Blieb, care to share your php code? Would be interesting to see how you'd implement it using php! (ps; dutch?)
find
iapiap Offline
Junior Member
Posts: 2
Joined: Dec 2010
Reputation: 0
Post: #35
@Blieb, I would also like to take a look at your code if possible, please Smile Thanks!
find
htpc guy Offline
Posting Freak
Posts: 1,182
Joined: Oct 2010
Reputation: 7
Location: Near St. Louis Mo
Post: #36
Hay, this is on Engadget!
http://www.engadget.com/2010/12/21/airpl...ext-video/


Congrats!

How to use Git
| AMD Athlon II X3 Triple Core Processor 2.9 GHz |GIGABYTE GA-MA785GM-US2H Mobo 2GB DDR2 Ram | MSI N430GT |
| Logitec Harmony One Remote| 52" Sharp Aquos LED TV | Demon AVR-X1000 |
find
Blieb Offline
Junior Member
Posts: 13
Joined: Dec 2010
Reputation: 0
Post: #37
iapiap Wrote:@Blieb, I would also like to take a look at your code if possible, please Smile Thanks!

Sure, but is it very buggy, I think this is not a good language voor making airplay in it.

PHP Code:
<?php
error_reporting
(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);

/* Turn on implicit output flushing so we see what we're getting
 * as it comes in. */
ob_implicit_flush();

$sendok "HTTP/1.1 200 OK\nContent-Length: 0\n\n";

$address '192.168.0.60';
$port 22555;

if ((
$sock socket_create(AF_INETSOCK_STREAMSOL_TCP)) === false) {
    echo 
"socket_create() failed: reason: " socket_strerror(socket_last_error()) . "\n";
}

if (
socket_bind($sock$address$port) === false) {
    echo 
"socket_bind() failed: reason: " socket_strerror(socket_last_error($sock)) . "\n";
}

if (
socket_listen($sock5) === false) {
    echo 
"socket_listen() failed: reason: " socket_strerror(socket_last_error($sock)) . "\n";
}

do {
    if ((
$msgsock socket_accept($sock)) === false) {
        echo 
"socket_accept() failed: reason: " socket_strerror(socket_last_error($sock)) . "\n";
        break;
    }
    
/* Send instructions. */

    
do {
        if (
false === ($buf socket_read($msgsock2048PHP_NORMAL_READ))) {
            echo 
"socket_read() failed: reason: " socket_strerror(socket_last_error($msgsock)) . "\n";
            break;
        }
        if (!
$buf trim($buf)) {
            continue;
        }
        echo 
"'$buf'\n";
        
$expl explode(" "$buf);
        if (
$expl[0] == "POST") { $cmd $expl[1]; $method $expl[0]; }
        if (
$expl[0] == "PUT") { $cmd $expl[1]; $method $expl[0]; }
        if (
$expl[0] == "GET") { $cmd $expl[1]; $method $expl[0]; }
        if (
$expl[0] == "Content-Location:") { $url $expl[1]; }
        if (
$expl[0] == "Content-Length:") { $contentlength $expl[1]; }
        if (
$expl[0] == "Start-Position:") { 
                
$postition $expl[1];
                echo 
"- Ik moet $url spelen!";
                
startvideo($url);
                
socket_write($msgsock$sendok);
        }

        if (
$expl[0] =="User-Agent:") {
                echo 
substr($cmd0,6);
                if (
$cmd == "/photo") {
                        
$photo "";
                        while (
strlen($photo) < $contentlength) {
                                
$photo .= socket_read($msgsock$contentlength);
                                echo 
"  -foto ontvangen" strlen($photo) . " of " $contentlength "\n"
                        }
                        
$File "/var/www/test.jpg"
                        
$Handle fopen($File'w');
                        
fwrite($Handletrim($photo)); 
                        
fclose($Handle);
                        
$cmd "";
                        
startpic("http://192.168.0.60/test.jpg");
                        
socket_write($msgsock$sendok);
                }
                if (
substr($cmd0,6) == "/scrub") {
                        
socket_write($msgsock$sendok);
                        echo 
"- send scrub reply\n";
                }
                if (
substr($cmd0,5) == "/rate") {
                        
$body "duration: 2:23\nposition: 31:11\n";
                        
$length strlen($reply);
                        
$reply "HTTP/1.1 200 OK\nContent-Length: $length\n\n";
                        
socket_write($msgsock$reply "\n\n" $body "\n\n");
                        echo 
"- send rate reply\n";
                }
                if (
$cmd == "/reverse") {
                {
                        
$reply "HTTP/1.1 101 Switching Protocols\r\nUpgrade: PTTH/1.0\r\nConnection: Upgrade\r\n\r\n\r\n";
                        
socket_write($msgsock$reply);
                        echo 
"- Sending switchting protocols\n";
                        
$cmd "";
                }
                break;
        }
        }

    } while (
true);
    
socket_close($msgsock);
} while (
true);

socket_close($sock);

function 
startvideo($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" $url "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
function 
startpic($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" $url "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
?>
avahi service file:

Code:
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_airplay._tcp</type>
<port>22555</port>
</service>
</service-group>


I was running the script on a other computer than xbmc is running. when used for photo's it saves photo to /var/www/test.jpg but I dit not know how to show it in xbmc.

I know it is crapy code. but it was just for testing. It should be written in a real language Tongue
find
Jaken Online
Senior Member
Posts: 156
Joined: Nov 2009
Reputation: 0
Post: #38
What about support for xbmc-to-ATV2G airplay. Is there hope for this? That would make these tiny black boxes do something useful. =)
find
iapiap Offline
Junior Member
Posts: 2
Joined: Dec 2010
Reputation: 0
Post: #39
Thanks @Blieb, that's very interesting - thanks for sharing.
find
JaccoH Offline
Member
Posts: 79
Joined: May 2009
Reputation: 0
Post: #40
@Blieb I've tried your code. It works. As far as I can tell only from youtube videos on my iPhone though. I would love for this to support audio as well. Would that be hard?
find
logictester Offline
Fan
Posts: 673
Joined: Oct 2008
Reputation: 0
Location: USA
Post: #41
Blieb Wrote:Sure, but is it very buggy, I think this is not a good language voor making airplay in it.

PHP Code:
<?php
error_reporting
(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);

/* Turn on implicit output flushing so we see what we're getting
 * as it comes in. */
ob_implicit_flush();

$sendok "HTTP/1.1 200 OK\nContent-Length: 0\n\n";

$address '192.168.0.60';
$port 22555;

if ((
$sock socket_create(AF_INETSOCK_STREAMSOL_TCP)) === false) {
    echo 
"socket_create() failed: reason: " socket_strerror(socket_last_error()) . "\n";
}

if (
socket_bind($sock$address$port) === false) {
    echo 
"socket_bind() failed: reason: " socket_strerror(socket_last_error($sock)) . "\n";
}

if (
socket_listen($sock5) === false) {
    echo 
"socket_listen() failed: reason: " socket_strerror(socket_last_error($sock)) . "\n";
}

do {
    if ((
$msgsock socket_accept($sock)) === false) {
        echo 
"socket_accept() failed: reason: " socket_strerror(socket_last_error($sock)) . "\n";
        break;
    }
    
/* Send instructions. */

    
do {
        if (
false === ($buf socket_read($msgsock2048PHP_NORMAL_READ))) {
            echo 
"socket_read() failed: reason: " socket_strerror(socket_last_error($msgsock)) . "\n";
            break;
        }
        if (!
$buf trim($buf)) {
            continue;
        }
        echo 
"'$buf'\n";
        
$expl explode(" "$buf);
        if (
$expl[0] == "POST") { $cmd $expl[1]; $method $expl[0]; }
        if (
$expl[0] == "PUT") { $cmd $expl[1]; $method $expl[0]; }
        if (
$expl[0] == "GET") { $cmd $expl[1]; $method $expl[0]; }
        if (
$expl[0] == "Content-Location:") { $url $expl[1]; }
        if (
$expl[0] == "Content-Length:") { $contentlength $expl[1]; }
        if (
$expl[0] == "Start-Position:") { 
                
$postition $expl[1];
                echo 
"- Ik moet $url spelen!";
                
startvideo($url);
                
socket_write($msgsock$sendok);
        }

        if (
$expl[0] =="User-Agent:") {
                echo 
substr($cmd0,6);
                if (
$cmd == "/photo") {
                        
$photo "";
                        while (
strlen($photo) < $contentlength) {
                                
$photo .= socket_read($msgsock$contentlength);
                                echo 
"  -foto ontvangen" strlen($photo) . " of " $contentlength "\n"
                        }
                        
$File "/var/www/test.jpg"
                        
$Handle fopen($File'w');
                        
fwrite($Handletrim($photo)); 
                        
fclose($Handle);
                        
$cmd "";
                        
startpic("http://192.168.0.60/test.jpg");
                        
socket_write($msgsock$sendok);
                }
                if (
substr($cmd0,6) == "/scrub") {
                        
socket_write($msgsock$sendok);
                        echo 
"- send scrub reply\n";
                }
                if (
substr($cmd0,5) == "/rate") {
                        
$body "duration: 2:23\nposition: 31:11\n";
                        
$length strlen($reply);
                        
$reply "HTTP/1.1 200 OK\nContent-Length: $length\n\n";
                        
socket_write($msgsock$reply "\n\n" $body "\n\n");
                        echo 
"- send rate reply\n";
                }
                if (
$cmd == "/reverse") {
                {
                        
$reply "HTTP/1.1 101 Switching Protocols\r\nUpgrade: PTTH/1.0\r\nConnection: Upgrade\r\n\r\n\r\n";
                        
socket_write($msgsock$reply);
                        echo 
"- Sending switchting protocols\n";
                        
$cmd "";
                }
                break;
        }
        }

    } while (
true);
    
socket_close($msgsock);
} while (
true);

socket_close($sock);

function 
startvideo($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" $url "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
function 
startpic($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" $url "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
?>
avahi service file:

Code:
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_airplay._tcp</type>
<port>22555</port>
</service>
</service-group>


I was running the script on a other computer than xbmc is running. when used for photo's it saves photo to /var/www/test.jpg but I dit not know how to show it in xbmc.

I know it is crapy code. but it was just for testing. It should be written in a real language Tongue

could you please share some instructions? thanks a lot
find
Blieb Offline
Junior Member
Posts: 13
Joined: Dec 2010
Reputation: 0
Post: #42
logictester Wrote:could you please share some instructions? thanks a lot

Some things need to be changed like xbmc ip somewere in the source, but stop using it!

The first poster published his python script. Use that one! it has less bugs Smile

http://code.google.com/p/play2wifi/
Don't forget to read the README on that site Smile


I wish I was able to get it running, but this person used the old api. Does this stil work in Dharma?
Or maybe not, It gives alot errors, I want to rewrite it in C Sad
(This post was last modified: 2010-12-22 03:52 by Blieb.)
find
joeblack2k Offline
Junior Member
Posts: 41
Joined: Oct 2009
Reputation: 0
Location: Netherlands - Leiden
Post: #43
Yeah got the .py code running Smile


edited the readme, how i got it to work..



Quote:Installation

This hack was developed on Ubuntu (but should also work on other linux systems). Therefore installation istruction will be for linux only (Ubuntu). It should be possible to port the code to other platform since it's only python. However I have no ideas about the dependencies (avahi for example).

apt-get install avahi-daemon
apt-get install python-twisted
apt-get install xbmc-eventclients-xbmc-send

copy the play2wifi.service script to /etc/avahi/services/.
restart avahi: "sudo service avahi-daemon restart"
pico play2wifi.cfg and edit the port number (default is 8080)
launch the script python play2wifi.py somewhere.
launch a video/podcast on the iThing and switch it over to xbmc.

Blieb is jou code php ? hoe start ik dat ?
find
Blieb Offline
Junior Member
Posts: 13
Joined: Dec 2010
Reputation: 0
Post: #44
joeblack2k Wrote:Yeah got the .py code running Smile


edited the readme, how i got it to work..





Blieb is jou code php ? hoe start ik dat ?

Why do you talk dutch?

Gewoon in console even doen:
php bla.php

Vergeet niet de url naar de xbmc te veranderen in de code. en ip adres van de server waar het script op draait. En de avahi-deamon config zoals je gedaan hebt in de post hierboven (dus niet nog een keer nodig). Maar is lang niet zo goed als de python script.

ok lets talk english again Tongue
find
mute Offline
Junior Member
Posts: 23
Joined: Sep 2009
Reputation: 0
Post: #45
Does this work for streaming from iTunes -> XBMC as well? I've got it setup, have connectivity between the laptop running iTunes and the Xbmc box. I can see the airplay service being advertised via Bonjour Browser, but for the life of me I can't figure out why it doesn't show up as a device in iTunes 10.1.1.

Edit: I am able to stream web based content (via AirFlick) to my xbmc, so I guess it's working on the XBMC side. If only I could figure out why iTunes doesn't recognize XBMC.
(This post was last modified: 2010-12-22 06:21 by mute.)
find
Thread Closed