@@ 43-59 (lines=17) @@ | ||
40 | * @param mixed $offset |
|
41 | * @param Playback $value |
|
42 | */ |
|
43 | public function offsetSet($offset, $value) |
|
44 | { |
|
45 | if (!$value instanceof Playback) { |
|
46 | throw new \InvalidArgumentException("Value must be of type Playback"); |
|
47 | } |
|
48 | parent::offsetSet($offset, $value); |
|
49 | ||
50 | // Remove playbacks when they are done playing |
|
51 | $value->oncePlaybackFinished(function (PlaybackFinished $playbackFinished) use ($value) { |
|
52 | if ($playbackFinished->getPlayback()->getId() === $value->getId()) { |
|
53 | $key = array_search($value, $this->getArrayCopy()); |
|
54 | if ($key !== false) { |
|
55 | $this->offsetUnset($key); |
|
56 | } |
|
57 | } |
|
58 | }); |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * @param Playback $value |
|
@@ 64-81 (lines=18) @@ | ||
61 | /** |
|
62 | * @param Playback $value |
|
63 | */ |
|
64 | public function append($value) |
|
65 | { |
|
66 | if (!$value instanceof Playback) { |
|
67 | throw new \InvalidArgumentException("Value must be of type Playback"); |
|
68 | } |
|
69 | parent::append($value); |
|
70 | ||
71 | // Remove playbacks when they are done playing |
|
72 | $this->phparia->getWsClient()->once('PlaybackFinished', |
|
73 | function (PlaybackFinished $playbackFinished) use ($value) { |
|
74 | if ($playbackFinished->getPlayback()->getId() === $value->getId()) { |
|
75 | $key = array_search($value, $this->getArrayCopy()); |
|
76 | if ($key !== false) { |
|
77 | $this->offsetUnset($key); |
|
78 | } |
|
79 | } |
|
80 | }); |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * Stop all the playbacks |