@@ -50,152 +50,155 @@ public function mainAction(): ResponseInterface
5050
5151 $ doc = $ this ->document ->getCurrentDocument ();
5252 $ pageNo = $ this ->requestData ['page ' ];
53- $ video = $ this ->getVideoInfo ($ doc , $ pageNo );
54- if ($ video === null ) {
53+ $ media = $ this ->getMediaplayerInfo ($ doc , $ pageNo );
54+ if ($ media === null ) {
5555 return $ this ->htmlResponse ();
5656 }
5757
5858 $ this ->addPlayerAssets ();
5959
60- $ this ->view ->assign ('video ' , $ video );
60+ $ this ->view ->assign ('media ' , $ media );
6161
6262 return $ this ->htmlResponse ();
6363 }
6464
6565 /**
66- * Build video info to be passed to the player template.
66+ * Build Mediaplayer info to be passed to the player template.
6767 *
6868 * @param AbstractDocument $doc
6969 * @param int $pageNo
7070 *
71- * @return ?mixed[] The video data, or `null` if no video source is found
71+ * @return ?mixed[] The Mediaplayer data, or `null` if no audio/ video-media source is found
7272 */
73- protected function getVideoInfo (AbstractDocument $ doc , int $ pageNo ): ?array
73+ protected function getMediaplayerInfo (AbstractDocument $ doc , int $ pageNo ): ?array
7474 {
75- // Get image file use groups
76- $ imageUseGroups = $ this ->useGroupsConfiguration ->getImage ();
75+ // Get audio file use groups
76+ $ audioUseGroups = $ this ->useGroupsConfiguration ->getAudio ();
7777 // Get video file use groups
7878 $ videoUseGroups = $ this ->useGroupsConfiguration ->getVideo ();
7979 $ mainVideoUseGroup = $ videoUseGroups [0 ] ?? '' ;
80+ // Merge audio and video file use groups without duplicates
81+ $ mediaplayerUseGroups = array_unique ([...$ audioUseGroups , ...$ videoUseGroups ]);
8082
8183 // Get thumbnail file use groups
8284 $ thumbnailUseGroups = $ this ->useGroupsConfiguration ->getThumbnail ();
83-
8485 // Get waveform file use groups
8586 $ waveformUseGroups = $ this ->useGroupsConfiguration ->getWaveform ();
87+ // Get image file use groups
88+ $ imageUseGroups = $ this ->useGroupsConfiguration ->getImage ();
8689
87- // Collect video file source URLs
90+ // Collect audio/ video-media file source URLs
8891 // TODO: This is for multiple sources (MPD, HLS, MP3, ...) - revisit, make sure it's ordered by preference!
89- $ videoSources = $ this ->collectVideoSources ($ doc , $ pageNo , $ videoUseGroups );
90- if (empty ($ videoSources )) {
92+ $ mediaplayerSources = $ this ->collectMediaSources ($ doc , $ pageNo , $ mediaplayerUseGroups );
93+ if (empty ($ mediaplayerSources )) {
9194 return null ;
9295 }
9396
9497 // List all chapters for chapter markers
95- $ videoChapters = $ this ->collectVideoChapters ($ doc );
98+ $ mediaChapters = $ this ->collectMediaChapters ($ doc );
9699
97- // Get additional video URLs
98- $ videoUrl = $ this ->collectAdditionalVideoUrls ($ doc , $ pageNo , $ thumbnailUseGroups , $ waveformUseGroups , $ imageUseGroups );
100+ // Get additional audio/ video-media URLs
101+ $ mediaUrl = $ this ->collectAdditionalMediaUrls ($ doc , $ pageNo , $ thumbnailUseGroups , $ waveformUseGroups , $ imageUseGroups );
99102
100103 return [
101- 'start ' => $ videoChapters [$ pageNo - 1 ]['timecode ' ] ?? '' ,
102- 'mode ' => $ this ->determineInitialMode ($ videoSources , $ mainVideoUseGroup ),
103- 'chapters ' => $ videoChapters ,
104+ 'start ' => $ mediaChapters [$ pageNo - 1 ]['timecode ' ] ?? '' ,
105+ 'mode ' => $ this ->determineInitialMode ($ mediaplayerSources , $ mainVideoUseGroup ),
106+ 'chapters ' => $ mediaChapters ,
104107 'metadata ' => $ doc ->getToplevelMetadata (),
105- 'sources ' => $ videoSources ,
106- 'url ' => $ videoUrl ,
108+ 'sources ' => $ mediaplayerSources ,
109+ 'url ' => $ mediaUrl ,
107110 ];
108111 }
109112
110113 /**
111- * Collects video sources for the given document.
114+ * Collects Audio/Video-Media sources for the given document.
112115 *
113- * @param AbstractDocument $doc The document object to collect video sources from
114- * @param int $pageNo The page number to collect video sources for
115- * @param string[] $videoUseGroups The array of video use groups to search for video sources
116+ * @param AbstractDocument $doc The document object to collect media sources from
117+ * @param int $pageNo The page number to collect media sources for
118+ * @param string[] $mediaplayerUseGroups The array of mediaplayer use groups to search for media sources
116119 *
117- * @return mixed[] An array of video sources with details like MIME type, URL, file ID, and frame rate
120+ * @return mixed[] An array of media sources with details like MIME type, URL, file ID, and frame rate
118121 */
119- private function collectVideoSources (AbstractDocument $ doc , int $ pageNo , array $ videoUseGroups ): array
122+ private function collectMediaSources (AbstractDocument $ doc , int $ pageNo , array $ mediaplayerUseGroups ): array
120123 {
121- $ videoSources = [];
122- $ videoFiles = $ this ->findFiles ($ doc , $ pageNo , $ videoUseGroups );
123- foreach ($ videoFiles as $ videoFile ) {
124- if ($ this ->isMediaMime ($ videoFile ['mimeType ' ])) {
125- $ fileMetadata = $ doc ->getMetadata ($ videoFile ['fileId ' ]);
124+ $ mediaplayerSources = [];
125+ $ mediaFiles = $ this ->findFiles ($ doc , $ pageNo , $ mediaplayerUseGroups );
126+ foreach ($ mediaFiles as $ mediaFile ) {
127+ if ($ this ->isMediaMime ($ mediaFile ['mimeType ' ])) {
128+ $ fileMetadata = $ doc ->getMetadata ($ mediaFile ['fileId ' ]);
126129
127- $ videoSources [] = [
128- 'fileGrp ' => $ videoFile ['fileGrp ' ],
129- 'mimeType ' => $ videoFile ['mimeType ' ],
130- 'url ' => $ videoFile ['url ' ],
131- 'fileId ' => $ videoFile ['fileId ' ],
130+ $ mediaplayerSources [] = [
131+ 'fileGrp ' => $ mediaFile ['fileGrp ' ],
132+ 'mimeType ' => $ mediaFile ['mimeType ' ],
133+ 'url ' => $ mediaFile ['url ' ],
134+ 'fileId ' => $ mediaFile ['fileId ' ],
132135 'frameRate ' => $ fileMetadata ['video_frame_rate ' ][0 ] ?? '' ,
133136 ];
134137 }
135138 }
136- return $ videoSources ;
139+ return $ mediaplayerSources ;
137140 }
138141
139142 /**
140- * Determine the initial mode (video or audio) based on the provided video sources and the main video use group.
143+ * Determine the initial mode (video or audio) based on the provided audio/ video-media sources and the main video use group.
141144 *
142- * @param mixed[] $videoSources An array of video sources with details like MIME type, URL, file ID, and frame rate
145+ * @param mixed[] $mediaplayerSources An array of media sources with details like MIME type, URL, file ID, and frame rate
143146 * @param string $mainVideoUseGroup The main video use group to prioritize
144147 *
145148 * @return string The initial mode ('video' or 'audio')
146149 */
147- private function determineInitialMode (array $ videoSources , string $ mainVideoUseGroup ): string
150+ private function determineInitialMode (array $ mediaplayerSources , string $ mainVideoUseGroup ): string
148151 {
149- foreach ($ videoSources as $ videoSource ) {
152+ foreach ($ mediaplayerSources as $ mediaplayerSource ) {
150153 // TODO: Better guess of initial mode?
151154 // Perhaps we could look for VIDEOMD/AUDIOMD in METS
152- if ($ videoSource ['fileGrp ' ] === $ mainVideoUseGroup || str_starts_with ($ videoSource ['mimeType ' ], 'video/ ' )) {
155+ if ($ mediaplayerSource ['fileGrp ' ] === $ mainVideoUseGroup || str_starts_with ($ mediaplayerSource ['mimeType ' ], 'video/ ' )) {
153156 return 'video ' ;
154157 }
155158 }
156159 return 'audio ' ;
157160 }
158161
159162 /**
160- * Collects all video chapters for chapter markers from the given AbstractDocument.
163+ * Collects all audio/ video-media chapters for chapter markers from the given AbstractDocument.
161164 *
162- * @param AbstractDocument $doc The AbstractDocument object to collect video chapters from
165+ * @param AbstractDocument $doc The AbstractDocument object to collect media chapters from
163166 *
164- * @return mixed[] An array of video chapters with details like file IDs, page numbers, titles, and timecodes
167+ * @return mixed[] An array of media chapters with details like file IDs, page numbers, titles, and timecodes
165168 */
166- private function collectVideoChapters (AbstractDocument $ doc ): array
169+ private function collectMediaChapters (AbstractDocument $ doc ): array
167170 {
168- $ videoChapters = [];
171+ $ mediaChapters = [];
169172 foreach ($ doc ->tableOfContents as $ entry ) {
170- $ this ->recurseChapters ($ entry , $ videoChapters );
173+ $ this ->recurseChapters ($ entry , $ mediaChapters );
171174 }
172- return $ videoChapters ;
175+ return $ mediaChapters ;
173176 }
174177
175178 /**
176- * Collects additional video URLs like poster and waveform for a given document, page number, thumb file use groups, and waveform file use groups.
179+ * Collects additional audio/ video-media URLs like poster and waveform for a given document, page number, thumb file use groups, and waveform file use groups.
177180 *
178181 * @param AbstractDocument $doc The document object
179182 * @param int $pageNo The page number
180183 * @param string[] $thumbnailUseGroups An array of thumb file use groups
181184 * @param string[] $waveformUseGroups An array of waveform file use groups
182185 * @param string[] $imageUseGroups An array of image file use groups
183186 *
184- * @return mixed[] An array containing additional video URLs like poster and waveform
187+ * @return mixed[] An array containing additional audio/ video-media URLs like poster and waveform
185188 */
186- private function collectAdditionalVideoUrls (AbstractDocument $ doc , int $ pageNo , array $ thumbnailUseGroups , array $ waveformUseGroups , array $ imageUseGroups ): array
189+ private function collectAdditionalMediaUrls (AbstractDocument $ doc , int $ pageNo , array $ thumbnailUseGroups , array $ waveformUseGroups , array $ imageUseGroups ): array
187190 {
188- $ videoUrl = [];
191+ $ mediaUrl = [];
189192
190193 $ showPoster = $ this ->settings ['constants ' ]['showPoster ' ] ?? null ;
191194 $ thumbFiles = $ this ->findFiles ($ doc , 0 , $ thumbnailUseGroups ); // 0 = for whole video (not just chapter)
192195 if (!empty ($ thumbFiles ) && (int ) $ showPoster === 1 ) {
193- $ videoUrl ['poster ' ] = $ thumbFiles [0 ];
196+ $ mediaUrl ['poster ' ] = $ thumbFiles [0 ];
194197 }
195198
196199 $ waveformFiles = $ this ->findFiles ($ doc , $ pageNo , $ waveformUseGroups );
197200 if (!empty ($ waveformFiles )) {
198- $ videoUrl ['waveform ' ] = $ waveformFiles [0 ];
201+ $ mediaUrl ['waveform ' ] = $ waveformFiles [0 ];
199202 }
200203
201204 $ showAudioLabelImage = $ this ->settings ['constants ' ]['showAudioLabelImage ' ] ?? null ;
@@ -204,10 +207,10 @@ private function collectAdditionalVideoUrls(AbstractDocument $doc, int $pageNo,
204207 && (int ) $ showAudioLabelImage === 1
205208 && Helper::filterFilesByMimeType ($ audioLabelImageFiles [0 ], ['image ' ], ['JPG ' ], 'mimeType ' )
206209 ) {
207- $ videoUrl ['audioLabelImage ' ] = $ audioLabelImageFiles [0 ];
210+ $ mediaUrl ['audioLabelImage ' ] = $ audioLabelImageFiles [0 ];
208211 }
209212
210- return $ videoUrl ;
213+ return $ mediaUrl ;
211214 }
212215
213216 /**
0 commit comments