MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / Play

Method Play

TombEngine/Specific/Video/Video.cpp:234–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232 }
233
234 bool VideoHandler::Play(const std::string& filename, VideoPlaybackMode mode, bool silent, bool loop)
235 {
236 auto fullVideoName = filename;
237
238 // At first, attempt to load video file with original filename. Then proceed with asset directory.
239 // Then, if not found, try all common video file extensions, and only quit if none are found.
240 if (!std::filesystem::is_regular_file(fullVideoName))
241 {
242 fullVideoName = _videoDirectory + filename;
243
244 if (!std::filesystem::is_regular_file(fullVideoName))
245 {
246 for (const auto& ext : VIDEO_EXTENSIONS)
247 {
248 if (std::filesystem::is_regular_file(fullVideoName + ext))
249 {
250 fullVideoName += ext;
251 break;
252 }
253 }
254
255 if (!std::filesystem::is_regular_file(fullVideoName))
256 {
257 TENLog("Video file " + fullVideoName + " not found.", LogLevel::Warning);
258 return false;
259 }
260 }
261 }
262
263 // Don't start playback if same video is already playing.
264 if (_player != nullptr)
265 {
266 if (libvlc_media_player_get_state(_player) == libvlc_Playing &&
267 _playbackMode == mode && _fileName == fullVideoName)
268 {
269 TENLog("Video file " + fullVideoName + " is already playing.", LogLevel::Warning);
270 return false;
271 }
272 }
273
274 // Stop previous player instance if it exists.
275 Stop();
276
277 _looped = loop;
278 _silent = silent;
279 _playbackMode = mode;
280 _fileName = fullVideoName;
281 _needRender = _updateInput = false;
282
283 auto* media = libvlc_media_new_path(_fileName.c_str());
284 if (media == nullptr)
285 {
286 TENLog("Failed to create media from path: " + _fileName, LogLevel::Error);
287 return false;
288 }
289
290 // VLC requires to initialize media. Load into player and release right away.
291 _player = libvlc_media_player_new_from_media(_vlcInstance, media);

Callers 2

ParseEffectsFunction · 0.45
GameMainFunction · 0.45

Calls 4

TENLogFunction · 0.85
PauseAllSoundsFunction · 0.85
c_strMethod · 0.45
filenameMethod · 0.45

Tested by

no test coverage detected