array( 'method' => 'POST', 'content' => $data)); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = fopen($url, 'rb', false, $ctx); //$fp = @fopen($url, 'rb', false, $ctx); //if (!$fp) { throw new Exception("Problem with $url, $php_errormsg");} $response = stream_get_contents($fp); //$response = @stream_get_contents($fp); //if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response; } function upnp_play_film($mediaserver_url, $mediaplayer_url, $film) { // Get nasename to be searched $info = pathinfo($film); $film = @basename($film,'.'.$info['extension']); // Search on the mediaserver $upnp_search = '0dc:title="%s"00'; $upnp_search_headers = 'SOAPACTION: "urn:schemas-upnp-org:service:ContentDirectory:1#Search"\ncontent-type: text/xml ;charset="utf-8"\nconnection: close'; $ret = do_post_request($mediaserver_url, sprintf($upnp_search,htmlspecialchars($film)),$upnp_search_headers); // Extract meta and url $r = simplexml_load_string($ret); $res = $r->xpath("//Result"); $r = simplexml_load_string($res[0]); $film_meta = ltrim(str_replace('','',$r->asXML())); $film_url = $r->item->res; // Play on the mediaplayer if (strlen($film_url) > 4) { // SetAVTransportURI $upnp_setav = '0%s%s'; $upnp_setav_headers = 'SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"\ncontent-type: text/xml ;charset="utf-8"\nconnection: close'; $ret = do_post_request($mediaplayer_url, sprintf($upnp_setav,htmlspecialchars($film_url),htmlspecialchars($film_meta)),$upnp_setav_headers); // Play $upnp_play = '01'; $upnp_play_headers = 'SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"\ncontent-type: text/xml ;charset="utf-8"\nconnection: close'; $ret = do_post_request($mediaplayer_url, $upnp_play,$upnp_play_headers); } return $film_url; } $film = "Your film"; // Full name, without path, and without extension print upnp_play_film($mediaserver_url, $mediaplayer_url, $film); ?>