| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include "../common.h" | ||
| 18 | #include "../log.h" | ||
| 19 | |||
| 20 | #include "PlaylistEntryPlaylist.h" | ||
| 21 | |||
| 22 | ✗ | PlaylistEntryPlaylist::PlaylistEntryPlaylist(Playlist* playlist, PlaylistEntryBase* parent) : | |
| 23 | PlaylistEntryBase(playlist, parent), | ||
| 24 | ✗ | m_playlist(NULL) { | |
| 25 | ✗ | m_type = "playlist"; | |
| 26 | ✗ | } | |
| 27 | |||
| 28 | ✗ | PlaylistEntryPlaylist::~PlaylistEntryPlaylist() { | |
| 29 | ✗ | if (m_playlist) { | |
| 30 | ✗ | m_playlist->Cleanup(); | |
| 31 | ✗ | delete m_playlist; | |
| 32 | } | ||
| 33 | ✗ | } | |
| 34 | |||
| 35 | /* | ||
| 36 | * | ||
| 37 | */ | ||
| 38 | ✗ | int PlaylistEntryPlaylist::Init(Json::Value& config) { | |
| 39 | ✗ | m_playlist = new Playlist(NULL); | |
| 40 | |||
| 41 | ✗ | if (!m_playlist) { | |
| 42 | ✗ | LogErr(VB_PLAYLIST, "Error creating sub playlist\n"); | |
| 43 | ✗ | return 0; | |
| 44 | } | ||
| 45 | |||
| 46 | ✗ | if ((config.isMember("name")) && | |
| 47 | ✗ | (!config["name"].asString().empty())) { | |
| 48 | ✗ | m_playlistName = config["name"].asString(); | |
| 49 | |||
| 50 | ✗ | if (m_playlistName.empty()) { | |
| 51 | ✗ | LogErr(VB_PLAYLIST, "Empty sub playlist name\n"); | |
| 52 | ✗ | return 0; | |
| 53 | } | ||
| 54 | ✗ | } else if (config.isMember("playlist")) { | |
| 55 | ✗ | m_playlist->Load(config["playlist"]); | |
| 56 | ✗ | m_playlist->RandomizeMainPlaylist(); | |
| 57 | } | ||
| 58 | |||
| 59 | ✗ | return PlaylistEntryBase::Init(config); | |
| 60 | } | ||
| 61 | |||
| 62 | /* | ||
| 63 | * | ||
| 64 | */ | ||
| 65 | ✗ | int PlaylistEntryPlaylist::StartPlaying(void) { | |
| 66 | ✗ | if (!m_playlist) | |
| 67 | ✗ | return 0; | |
| 68 | |||
| 69 | ✗ | if (!CanPlay()) { | |
| 70 | ✗ | FinishPlay(); | |
| 71 | ✗ | return 0; | |
| 72 | } | ||
| 73 | |||
| 74 | ✗ | if (!m_playlistName.empty()) { | |
| 75 | ✗ | if (!m_playlist->Load(m_playlistName.c_str())) { | |
| 76 | ✗ | return 0; | |
| 77 | } | ||
| 78 | ✗ | m_playlist->RandomizeMainPlaylist(); | |
| 79 | } | ||
| 80 | |||
| 81 | ✗ | if (!m_playlist->Start()) | |
| 82 | ✗ | return 0; | |
| 83 | |||
| 84 | ✗ | return PlaylistEntryBase::StartPlaying(); | |
| 85 | } | ||
| 86 | |||
| 87 | /* | ||
| 88 | * | ||
| 89 | */ | ||
| 90 | ✗ | int PlaylistEntryPlaylist::Process(void) { | |
| 91 | ✗ | if (!m_playlist->Process()) | |
| 92 | ✗ | FinishPlay(); | |
| 93 | |||
| 94 | ✗ | return PlaylistEntryBase::Process(); | |
| 95 | } | ||
| 96 | |||
| 97 | /* | ||
| 98 | * | ||
| 99 | */ | ||
| 100 | ✗ | int PlaylistEntryPlaylist::Stop(void) { | |
| 101 | ✗ | m_playlist->StopNow(); | |
| 102 | |||
| 103 | ✗ | return PlaylistEntryBase::Stop(); | |
| 104 | } | ||
| 105 | |||
| 106 | /* | ||
| 107 | * | ||
| 108 | */ | ||
| 109 | ✗ | void PlaylistEntryPlaylist::Dump(void) { | |
| 110 | ✗ | LogDebug(VB_PLAYLIST, "Playlist Name: %s\n", m_playlistName.c_str()); | |
| 111 | ✗ | } | |
| 112 | |||
| 113 | /* | ||
| 114 | * | ||
| 115 | */ | ||
| 116 | ✗ | Json::Value PlaylistEntryPlaylist::GetConfig(void) { | |
| 117 | ✗ | Json::Value result = PlaylistEntryBase::GetConfig(); | |
| 118 | ✗ | Json::Value playlistConfig = m_playlist->GetConfig(); | |
| 119 | |||
| 120 | ✗ | MergeJsonValues(result, playlistConfig); | |
| 121 | |||
| 122 | ✗ | return result; | |
| 123 | ✗ | } | |
| 124 |