1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Request; |
6
|
|
|
|
7
|
|
|
class MediaTag |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param bool|null $allowAdjustSeekPositionForward Whether seeking forward is allowed |
11
|
|
|
* @param bool|null $allowAdjustSeekPositionBackwards Whether seeking backwards is allowed |
12
|
|
|
* @param bool|null $allowNext Whether next track is allowed |
13
|
|
|
* @param bool|null $allowPrevious Whether previous track is allowed |
14
|
|
|
* @param AudioTrack|null $audioTrack Audio track type |
15
|
|
|
* @param Entity[]|null $entities Array of entities |
16
|
|
|
* @param bool|null $muted Whether audio is muted |
17
|
|
|
* @param int|null $positionInMilliseconds Current position in milliseconds |
18
|
|
|
* @param MediaState|null $state Current media state |
19
|
|
|
* @param string|null $url Media URL |
20
|
|
|
*/ |
21
|
4 |
|
public function __construct( |
22
|
|
|
public ?bool $allowAdjustSeekPositionForward = null, |
23
|
|
|
public ?bool $allowAdjustSeekPositionBackwards = null, |
24
|
|
|
public ?bool $allowNext = null, |
25
|
|
|
public ?bool $allowPrevious = null, |
26
|
|
|
public ?AudioTrack $audioTrack = null, |
27
|
|
|
public ?array $entities = null, |
28
|
|
|
public ?bool $muted = null, |
29
|
|
|
public ?int $positionInMilliseconds = null, |
30
|
|
|
public ?MediaState $state = null, |
31
|
|
|
public ?string $url = null, |
32
|
|
|
) { |
33
|
4 |
|
$this->entities = $this->entities ?? []; |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
public static function fromAmazonRequest(array $amazonRequest): self |
37
|
|
|
{ |
38
|
4 |
|
$entities = []; |
39
|
4 |
|
if (isset($amazonRequest['entities']) && is_array($amazonRequest['entities'])) { |
40
|
2 |
|
foreach ($amazonRequest['entities'] as $entityData) { |
41
|
1 |
|
$entities[] = Entity::fromAmazonRequest($entityData); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
4 |
|
return new self( |
46
|
4 |
|
allowAdjustSeekPositionForward: $amazonRequest['allowAdjustSeekPositionForward'] ?? null, |
47
|
4 |
|
allowAdjustSeekPositionBackwards: $amazonRequest['allowAdjustSeekPositionBackwards'] ?? null, |
48
|
4 |
|
allowNext: $amazonRequest['allowNext'] ?? null, |
49
|
4 |
|
allowPrevious: $amazonRequest['allowPrevious'] ?? null, |
50
|
4 |
|
audioTrack: isset($amazonRequest['audioTrack']) ? AudioTrack::tryFrom($amazonRequest['audioTrack']) : null, |
51
|
4 |
|
entities: $entities, |
52
|
4 |
|
muted: $amazonRequest['muted'] ?? null, |
53
|
4 |
|
positionInMilliseconds: $amazonRequest['positionInMilliseconds'] ?? null, |
54
|
4 |
|
state: isset($amazonRequest['state']) ? MediaState::tryFrom($amazonRequest['state']) : null, |
55
|
4 |
|
url: $amazonRequest['url'] ?? null, |
56
|
4 |
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|