1 | <?php |
||
14 | class Segments implements DumpableInterface, \Iterator, \ArrayAccess |
||
15 | { |
||
16 | private $segments = []; |
||
17 | |||
18 | private $m3u8; |
||
19 | |||
20 | private $position = 0; |
||
21 | |||
22 | 2 | public function __construct(M3u8 $m3u8) |
|
26 | |||
27 | public function rewind() |
||
28 | { |
||
29 | $this->position = 0; |
||
30 | } |
||
31 | |||
32 | public function current() |
||
36 | |||
37 | 1 | public function key() |
|
38 | 1 | { |
|
39 | 1 | return $this->position; |
|
40 | 1 | } |
|
41 | |||
42 | public function next() |
||
46 | |||
47 | public function valid() |
||
51 | |||
52 | public function offsetSet($offset, $value) |
||
64 | |||
65 | /** |
||
66 | * @return Chrisyue\PhpM3u8\Segment |
||
67 | */ |
||
68 | 1 | public function offsetGet($offset) |
|
72 | |||
73 | /** |
||
74 | * @return bool |
||
75 | */ |
||
76 | public function offsetExists($offset) |
||
77 | { |
||
78 | return isset($this->segments[$offset]); |
||
79 | } |
||
80 | |||
81 | public function offsetUnset($offset) |
||
82 | { |
||
83 | unset($this->segments[$offset]); |
||
84 | } |
||
85 | |||
86 | 1 | public function add(Segment $segment) |
|
87 | { |
||
88 | 1 | $this->segments[] = $segment; |
|
89 | 1 | } |
|
90 | |||
91 | /** |
||
92 | * @return int|float |
||
93 | */ |
||
94 | 1 | public function getDuration() |
|
95 | { |
||
96 | 1 | $duration = 0; |
|
97 | 1 | foreach ($this->segments as $segment) { |
|
98 | 1 | $duration += $segment->getDuration(); |
|
99 | 1 | } |
|
100 | |||
101 | 1 | return $duration; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @return Chrisyue\PhpM3u8\Segment |
||
106 | */ |
||
107 | public function getFirst() |
||
108 | { |
||
109 | $first = reset($this->segments); |
||
110 | if (false !== $first) { |
||
111 | return $first; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @return int |
||
117 | */ |
||
118 | public function count() |
||
119 | { |
||
120 | return count($this->segments); |
||
121 | } |
||
122 | |||
123 | 1 | public function readLines(array &$lines) |
|
144 | |||
145 | public function dump() |
||
153 | } |
||
154 |