-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCCDefaultMediaPlayer.php
86 lines (73 loc) · 3.23 KB
/
CCDefaultMediaPlayer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
// Make it really easy to play videos by providing functions for the Chromecast Default Media Player
require_once("CCBaseSender.php");
class CCDefaultMediaPlayer extends CCBaseSender
{
public $appid="CC1AD845";
public function play($url,$streamType,$contentType,$autoPlay,$currentTime) {
// Start a playing
// First ensure there's an instance of the DMP running
$this->launch();
$json = '{"type":"LOAD","media":{"contentId":"' . $url . '","streamType":"' . $streamType . '","contentType":"' . $contentType . '"},"autoplay":' . $autoPlay . ',"currentTime":' . $currentTime . ',"requestId":921489134}';
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media", $json);
$r = "";
while (!preg_match("/\"playerState\":\"PLAYING\"/",$r)) {
$r = $this->chromecast->getCastMessage();
sleep(1);
}
// Grab the mediaSessionId
preg_match("/\"mediaSessionId\":([^\,]*)/",$r,$m);
$this->mediaid = $m[1];
}
public function pause() {
// Pause
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"PAUSE", "mediaSessionId":' . $this->mediaid . ', "requestId":1}');
$this->chromecast->getCastMessage();
}
public function restart() {
// Restart (after pause)
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"PLAY", "mediaSessionId":' . $this->mediaid . ', "requestId":1}');
$this->chromecast->getCastMessage();
}
public function seek($secs) {
// Seek
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"SEEK", "mediaSessionId":' . $this->mediaid . ', "currentTime":' . $secs . ',"requestId":1}');
$this->chromecast->getCastMessage();
}
public function stop() {
// Stop
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"STOP", "mediaSessionId":' . $this->mediaid . ', "requestId":1}');
$this->chromecast->getCastMessage();
}
public function getStatus() {
// Stop
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.media",'{"type":"GET_STATUS", "mediaSessionId":' . $this->mediaid . ', "requestId":1}');
$r = $this->chromecast->getCastMessage();
preg_match("/{\"type.*/",$r,$m);
return json_decode($m[0]);
}
public function Mute() {
// Mute a video
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.receiver", '{"type":"SET_VOLUME", "volume": { "muted": true }, "requestId":1 }');
$this->chromecast->getCastMessage();
}
public function UnMute() {
// Mute a video
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.receiver", '{"type":"SET_VOLUME", "volume": { "muted": false }, "requestId":1 }');
$this->chromecast->getCastMessage();
}
public function SetVolume($volume) {
// Mute a video
$this->launch(); // Auto-reconnects
$this->chromecast->sendMessage("urn:x-cast:com.google.cast.receiver", '{"type":"SET_VOLUME", "volume": { "level": ' . $volume . ' }, "requestId":1 }');
$this->chromecast->getCastMessage();
}
}
?>