Servus. In einem anderen Post habe ich schonmal darüber diskutiert ein Internetradio (Musicpal von Freecom) über PHP anzusteuern.
Dank „jonofe“ aus dem Freecom-Forum gibt es jetzt so ein Skript.
Ansich könnte ich ja jetzt zufrieden sein, nur bekomme ich es nicht zum laufen.
Man muss dazu sagen, dass ich aus der Delphi/Pascal Welt komme und bei PHP einiges anders ist.
Wie kann ich denn den Constructor von einem Script aufrufen. Bei dem oben erwähnten Skript müssen da nämlich IP, Logindaten … übergeben werden.
ich habe da schonmal so angefangen (nur so ansatzweise).
<?
require(MusicPal.ips.php)
$mp_cfg = array(ip="192.168.178.41",user="Admin",password="admin");
musicpal($mp_cfg);
// Funktionsaufruf ????
if musicpal.is_on ( ... mach irgendwas
?>
und hier das Skript welches ich verwenden will …
<?php
//
// The class musicpal defines an musicpal object to control a musicpal device.
// It consists of several control functions like power_down, power_up, etc.
// The constructor expects an associative array containing the keys "ip", "user", "password"
// with the appropriate values
//
class musicpal
{
var $ip;
var $user;
var $password;
var $state;
//
// musicpal(): creates the object and saves the IP address, user name and password
// to access the musciapl device
//
function musicpal($mp_cfg)
{
$this->ip = $mp_cfg["ip"];
$this->user = $mp_cfg["user"];
$this->password = $mp_cfg["password"];
$this->get_state();
}
//
// power_up(): switches the musicpal on from standby
//
function power_up()
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/ipc_send?power_up";
http_get($get_url);
}
//
// power_down(): switches the musicpal down to standby
//
function power_down()
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/ipc_send?power_down";
http_get($get_url);
}
function volume($vol)
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/admin.cgi?f=volume_set&v=".$vol;
http_get($get_url);
}
function favorite($no)
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/admin.cgi?f=favorites&n=../favorites.html&a=p&i=".$no;
http_get($get_url);
}
function play_pause()
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/admin.cgi?f=play_pause";
http_get($get_url);
}
function get_state()
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/state.cgi?fav=0";
$state_xml = http_get($get_url);
$state_xml = substr($state_xml,strpos($state_xml,"<volume>"));
$this->state = simplexml_load_string("<state>".$state_xml);
}
function is_on()
{
$this->get_state();
if ($this->state->power_state == 1)
return TRUE;
else
return FALSE;
}
function is_off()
{
$this->get_state();
if ($this->state->power_state == 1)
return FALSE;
else
return TRUE;
}
//
// This functions sets the brightness of the MusicPal display depending of its status
//
// $brightness: value in range from 0 to 10
//
// $displayStatus indicates which of the following 3 status you want to change
// "active" - brightness when MP is in active mode
// "sleeping" - brightness when MP is in dleeping mode
// "sleep_timer" - brightness when sleep timer of MP is active
//
function brightness($brightness,$mpStatus="active")
{
$post_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/admin.cgi?f=display_brightness_".$mpStatus."&n=../display_brightness_".$mpStatus.".html";
$post_data = array('brightness'=>$brightness, 'apply' => 'Verwenden');
http_post_fields($post_url,$post_data);
}
function is_playing()
{
$this->get_state();
if ($this->state->player_state == 1)
return TRUE;
else
return FALSE;
}
function pause()
{
if ($this->is_playing())
$this->play_pause();
}
function play()
{
if (!$this->is_playing())
$this->play_pause();
}
function get_volume()
{
$this->get_state();
return $this->state->volume;
}
function is_radio()
{
if ($this->state->is_internet_radio == 1)
return TRUE;
else
return FALSE;
}
function send_message($rows)
{
$msg = rawurlencode(implode("§",$rows));
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/ipc_send?show_list%20".$msg;
echo "URL: ".$get_url."
";
http_get($get_url);
}
function confirm_message()
{
$get_url = "http://".$this->user.":".$this->password."@".$this->ip."/admin/cgi-bin/ipc_send?menu_collapse";
if (!$this->is_on())
{
$this->power_up();
sleep(1);
http_get($get_url);
$this->power_down();
} else
http_get($get_url);
}
}
?>