Implemented a better way to mute videos.

This commit is contained in:
Leon Styhre 2020-12-20 20:37:31 +01:00
parent 46c178af1d
commit cfff577549

View file

@ -30,7 +30,8 @@
libvlc_instance_t* VideoVlcComponent::mVLC = nullptr; libvlc_instance_t* VideoVlcComponent::mVLC = nullptr;
// VLC prepares to render a video frame. // VLC prepares to render a video frame.
static void* lock(void* data, void** p_pixels) { static void* lock(void* data, void** p_pixels)
{
struct VideoContext* c = reinterpret_cast<struct VideoContext*>(data); struct VideoContext* c = reinterpret_cast<struct VideoContext*>(data);
SDL_LockMutex(c->mutex); SDL_LockMutex(c->mutex);
SDL_LockSurface(c->surface); SDL_LockSurface(c->surface);
@ -39,14 +40,16 @@ static void* lock(void* data, void** p_pixels) {
} }
// VLC just rendered a video frame. // VLC just rendered a video frame.
static void unlock(void* data, void* /*id*/, void *const* /*p_pixels*/) { static void unlock(void* data, void* /*id*/, void *const* /*p_pixels*/)
{
struct VideoContext* c = reinterpret_cast<struct VideoContext*>(data); struct VideoContext* c = reinterpret_cast<struct VideoContext*>(data);
SDL_UnlockSurface(c->surface); SDL_UnlockSurface(c->surface);
SDL_UnlockMutex(c->mutex); SDL_UnlockMutex(c->mutex);
} }
// VLC wants to display a video frame. // VLC wants to display a video frame.
static void display(void* /*data*/, void* /*id*/) { static void display(void* /*data*/, void* /*id*/)
{
// Data to be displayed. // Data to be displayed.
} }
@ -357,11 +360,17 @@ void VideoVlcComponent::startVideo()
// Setup the media player. // Setup the media player.
mMediaPlayer = libvlc_media_player_new_from_media(mMedia); mMediaPlayer = libvlc_media_player_new_from_media(mMedia);
libvlc_media_player_play(mMediaPlayer);
libvlc_video_set_callbacks(mMediaPlayer, lock, unlock, display,
reinterpret_cast<void*>(&mContext));
libvlc_video_set_format(mMediaPlayer, "RGBA", static_cast<int>(mVideoWidth),
static_cast<int>(mVideoHeight), static_cast<int>(mVideoWidth * 4));
if ((!Settings::getInstance()->getBool("GamelistVideoAudio") && if ((!Settings::getInstance()->getBool("GamelistVideoAudio") &&
!mScreensaverMode) || !mScreensaverMode) ||
(!Settings::getInstance()->getBool("ScreensaverVideoAudio") && (!Settings::getInstance()->getBool("ScreensaverVideoAudio") &&
mScreensaverMode)) { mScreensaverMode)) {
libvlc_audio_set_mute(mMediaPlayer, 1); libvlc_audio_set_volume(mMediaPlayer, 0);
} }
else { else {
libvlc_audio_set_mute(mMediaPlayer, 0); libvlc_audio_set_mute(mMediaPlayer, 0);
@ -369,12 +378,6 @@ void VideoVlcComponent::startVideo()
Settings::getInstance()->getInt("SoundVolumeVideos")); Settings::getInstance()->getInt("SoundVolumeVideos"));
} }
libvlc_media_player_play(mMediaPlayer);
libvlc_video_set_callbacks(mMediaPlayer, lock, unlock, display,
reinterpret_cast<void*>(&mContext));
libvlc_video_set_format(mMediaPlayer, "RGBA", static_cast<int>(mVideoWidth),
static_cast<int>(mVideoHeight), static_cast<int>(mVideoWidth * 4));
// Update the playing state. // Update the playing state.
mIsPlaying = true; mIsPlaying = true;
mFadeIn = 0.0f; mFadeIn = 0.0f;
@ -429,13 +432,12 @@ void VideoVlcComponent::handleLooping()
} }
else { else {
libvlc_media_player_set_media(mMediaPlayer, mMedia); libvlc_media_player_set_media(mMediaPlayer, mMedia);
libvlc_media_player_play(mMediaPlayer);
if ((!Settings::getInstance()->getBool("GamelistVideoAudio") && if ((!Settings::getInstance()->getBool("GamelistVideoAudio") &&
!mScreensaverMode) || (!Settings::getInstance()-> !mScreensaverMode) || (!Settings::getInstance()->
getBool("ScreensaverVideoAudio") && mScreensaverMode)) getBool("ScreensaverVideoAudio") && mScreensaverMode))
libvlc_audio_set_mute(mMediaPlayer, 1); libvlc_audio_set_volume(mMediaPlayer, 0);
libvlc_media_player_play(mMediaPlayer);
} }
} }
} }