multimediamanager::MediaAudioOwnership_t MultimediaManager::CanPlayAudio()
{
// TODO this applies only for storage. For BT, it is not straightforward
multimediamanager::MediaAudioOwnership_t ret
= multimediamanager::MediaAudioOwnership_t::MEDIA_AUDIO_OWNERSHIP_UNTAKEN;
auto audioMan = services::MultimediaServiceProvider::GetInstance()->get_AudioManager();
if (audioMan->getIsAudioMine() == true)
{
ret = multimediamanager::MediaAudioOwnership_t::MEDIA_AUDIO_OWNERSHIP_CAN_PLAY;
}
return ret;
}
multimediamanager::StorageSourceConnection_t
MultimediaManager::GetStorageSourceConnectionState(multimediamanager::MediaSources in0)
{
multimediamanager::StorageSourceConnection_t state = multimediamanager::StorageSourceConnection_t::NOT_CONNECTED;
if (MulM::MediaSourceManager::IsStorageSource(in0) == true)
{
MulM::MediaStorageSource* sourceCtx = m_sourceManager->GetMediaStorageSourceHandler(in0);
state = MulMAdaptor::MediaSourceToDBus(sourceCtx->GetConnectionState());
}
qInfo() << multimediamanager::helper::MediaSourcesString(in0) << state;
return state;
}
bool MultimediaManager::IsStorageSourceKnown(multimediamanager::MediaSources in0)
{
bool ret = false;
if (MulM::MediaSourceManager::IsRemovableSource(in0) == true)
{
MulM::MediaRemovableSource* sourceCtx = m_sourceManager->GetMediaRemovableSourceHandler(in0);
ret = sourceCtx->IsNewDevice();
}
return ret;
}
void MultimediaManager::BrowseMediaSource(multimediamanager::MediaSources source, const QString& path)
{
if (m_sourceManager->IsStorageSource(source) == true)
{
// You can Submit one of the following and obtaining the same behaviour
// /media/usb1/pathtobrowse - pathtobrowse
QString targetPathFixed = FileM::RelativePathToAbsolute(path, source);
qInfo() << "Browsing by" << path << multimediamanager::helper::MediaSourcesString(source) << "Absolute"
<< targetPathFixed;
(void) m_fileManager->DoBrowse(m_sourceManager->GetMediaStorageSourceHandler(source), targetPathFixed);
}
else if (m_sourceManager->IsBTSource(source) == true)
{
qWarning() << "Browsing Media Source by itemId not handled for sources = Bluetooth";
}
}
void MultimediaManager::BrowseMediaSource(multimediamanager::MediaSources source, int itemId)
{
if (m_sourceManager->IsBTSource(source) == true)
{
m_btFileManager->BrowseToItem(source, itemId);
}
else
{
qWarning() << "Browsing Media Source by itemId not handled for sources != Bluetooth";
}
}
int MultimediaManager::getCurrentNowPlayingIndex(multimediamanager::MediaSources source)
{
int ret = 0;
auto ISourceH = m_sourceManager->GetMediaSourceHandler(source);
if (ISourceH != nullptr)
{
auto pbProgress = ISourceH->GetPlaybackProgress();
ret = pbProgress.Index;
}
return ret;
}
multimediamanager::PlaybackStatus_t MultimediaManager::getCurrentPlaybackStatus()
{
auto player = getCurrenPlayer();
multimediamanager::PlaybackStatus_t status
= player ? player->GetPlaybackStatus() : multimediamanager::PlaybackStatus_t::PB_NOT_SET;
return status;
}
if (m_playerInterface->IsPlaylistEmpty() == true)
{
auto allSongs = StorageSourceH->GetSongListTotal();
int indexToSet = 0;
m_playerInterface->OnPlayThisList(allSongs, indexToSet);
}
}
PLAYER_SAFE_CALL(PlayPrev(count))
}
void MultimediaManager::playItem(int index)
{
const multimediamanager::MediaSources currentSource = m_sourceManager->GetCurrentSource();
if (m_sourceManager->IsStorageSource(currentSource) == true)
{
auto sourceHandler = m_sourceManager->GetMediaStorageSourceHandler(currentSource);
const int currentIndex = sourceHandler->GetCurrentMediaIndex();
code
// Check if index is valid considering our nowPlayingList
const auto& nowPList = sourceHandler->GetNowPlayingSongList();
if ((index < 0) || (nowPList.count() <= index))
{
qInfo() << "Index is invalid. NowP Count is" << nowPList.count() << "Index" << index;
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_STOPPED);
}
else
{
// Set LastUserPlaybackStatus
sourceHandler->SetLastUserPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_PLAYING);
qInfo() << "index: " << index << " currentIndex:" << currentIndex;
qInfo() << "current media source: " << currentSource;
qint64 lastPosition = 0;
m_playerInterface->SetPlayingIndex(index);
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_PLAYING);
if (currentIndex == index)
{
if (sourceHandler != nullptr)
{
lastPosition = sourceHandler->GetPlaybackProgress().ElapsedMsec;
}
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_PAUSED);
qInfo() << " resume playing from last position (" << (lastPosition) << ")"
<< multimediamanager::helper::millisecToString(lastPosition);
auto seekAndPlay = [this, lastPosition]() {
// TODO Improve SeekAndPlay to take also current source: if seekable changes but source is not the same, then do nothing!
// Or add a StateMachine for playing status
const Art::PlaybackStatus pbStatus = m_audioPlayer->playbackStatus();
const bool seekable = m_audioPlayer->isSeekable();
if (seekable && Art::PlaybackStatus::kStopped != pbStatus)
{
qInfo() << "resume playing from last position "
<< multimediamanager::helper::millisecToString(lastPosition) << " and disconnect";
seekTo(static_cast<int>(lastPosition));
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_PLAYING);
}
};
SeekAndPlay::doSeekAndPlay(seekAndPlay, m_audioPlayer, this);
}
}
}
else if (m_sourceManager->IsBTSource(currentSource) == true)
{
m_bluetoothPlayer->SetPlayingIndex(index);
}
}
void MultimediaManager::playPlaylist(const QString& path)
{
multimediamanager::MediaSources currentSource = m_sourceManager->GetCurrentSource();
// Bugged. No check of the audioToken ? is this function used by LIMU?
if (m_sourceManager->IsBTSource(currentSource) == true)
{
qInfo() << "Not valid for BT Sources";
}
else if (m_sourceManager->IsStorageSource(currentSource) && MultiMediaUtils::isPlaylist(path))
{
qInfo() << "Loading Playlist" << path;
m_playerInterface->OnPlayPlaylist(path);
}
}
auto storageSourceHandle = m_sourceManager->GetMediaStorageSourceHandler(source);
if (storageSourceHandle != nullptr)
{
storageSourceHandle->AddFavourites(absPaths, removeExisting);
}
// Retrieve new favourite list and trigger emit through interface.
getFavouritesAudioList(source);
triggerInternalMemoryReparse(); /* trigger anyway as copy may be interrupted */
m_adaptor->OperationDone(opID, filemanager::OperationType_t::FILE_OP_COPY, success);
triggerInternalMemoryReparse(); /* trigger anyway as copy may be interrupted */
const auto result
= success ? filemanager::FileOperationResult_t::Success : filemanager::FileOperationResult_t::ExecutionProblem;
m_adaptor->OperationDone(opID, filemanager::OperationType_t::FILE_OP_MOVE, result);
triggerInternalMemoryReparse(); /* trigger anyway as copy may be interrupted */
const auto result
= success ? filemanager::FileOperationResult_t::Success : filemanager::FileOperationResult_t::ExecutionProblem;
m_adaptor->OperationDone(opID, filemanager::OperationType_t::FILE_OP_REMOVE, result);
triggerInternalMemoryReparse(); /* trigger anyway as copy may be interrupted */
const auto result
= success ? filemanager::FileOperationResult_t::Success : filemanager::FileOperationResult_t::ExecutionProblem;
m_adaptor->OperationDone(opID, filemanager::OperationType_t::FILE_OP_RENAME, result);
auto sourceCtx = m_sourceManager->GetMediaStorageSourceHandler(source);
// If it is the last time this slot is triggered (SINGLE or FIRST)
bool isSingleTime = (order == multimediamanager::ListInfo_t::SINGLE);
bool isFirstTime = (order == multimediamanager::ListInfo_t::FIRST);
bool isLastTime = (order == multimediamanager::ListInfo_t::LAST);
// Clear lists if it is first time ever (single or first chunk)
if ((isSingleTime == true) || (isFirstTime == true))
{
sourceCtx->ClearNowPlayingSongList();
sourceCtx->ClearListTotal();
}
// Add to lists (SongListTotal + NowPlaying)
if (sourceCtx != nullptr)
{
sourceCtx->AddToSongListTotal(audioList);
sourceCtx->AddToNowPlayingSongList(audioList);
}
// If it is related to current source, then update also the player interface
if ((m_sourceManager != nullptr) && (sourceCtx != nullptr))
{
if (m_sourceManager->GetCurrentSource() == sourceCtx->GetSourceType())
{
if ((isSingleTime == true) || (isFirstTime == true))
{
m_playerInterface->SetNowPlayingList(audioList);
}
else
{
m_playerInterface->UpdateNowPlayingList(audioList);
}
}
else
{
qDebug() << "current source" << m_sourceManager->GetCurrentSource();
qDebug() << "source type" << sourceCtx->GetSourceType();
}
// reset CurrentMediaIndex only for new USB media.
// for hdd we have index set from persistence.
// We reset mediaIndex only if invalid
// IE Consider the case in which we are playing from HDD and user adds a new element
// this triggers a re-scan, and we are here in a blink of an eye. What we do ? ;)
if (sourceCtx->GetCurrentMediaIndex() < 0)
{
sourceCtx->SetCurrentMediaIndex(0);
}
signalSourceInfo(source, audioList, audioList, order);
if ((isSingleTime == true) || (isLastTime == true))
{
sourceCtx->SetConnectionState(MulM::MediaSource::StorageConnectionState::kReady);
m_adaptor->StorageSourceConnectionStateChanged(
source, MulMAdaptor::MediaSourceToDBus(sourceCtx->GetConnectionState()));
printSourcesStatus();
}
else if (isFirstTime == true)
{
sourceCtx->SetConnectionState(MulM::MediaSource::StorageConnectionState::kParsingMetadata);
}
}
else
{
m_adaptor->StorageSourceConnectionStateChanged(source,
multimediamanager::StorageSourceConnection_t::NOT_CONNECTED);
}
if (usbInfo == UsbId_enum::USB_1)
{
source = multimediamanager::MediaSources::MEDIA_USB1;
}
else if (usbInfo == UsbId_enum::USB_2)
{
source = multimediamanager::MediaSources::MEDIA_USB2;
}
else
{
}
if (source == multimediamanager::MediaSources::MEDIA_NOT_SET)
{
}
else
{
m_sourceManager->OnUsbDisconnectedInfo(source);
m_adaptor->StorageSourceConnectionStateChanged(
source, MulMAdaptor::MediaSourceToDBus(MulM::MediaRemovableSource::StorageConnectionState::kInvalid));
// Post Event
m_stateMachine->postEvent(new statemachine::StorageSourceDisconnectedEvent(source));
// if the source was our current media, then stop the playback
if (m_sourceManager->GetCurrentSource() == source)
{
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_STOPPED);
m_playerInterface->ClearQueue();
}
}
}
void MultimediaManager::OnSystemEventCommand(SysFuncMode_t sysEventCmd)
{
/* not used */
Q_UNUSED(sysEventCmd);
}
#undef SAFE_CALL
#undef PLAYER_SAFE_CALL
//****************************************************************************
//****************************************************************************
can u find a spot where parsing media files in usb is done?
kWaitIndexingStart
Invoke scanning: The actual parsing of media files is done by calling DoScanSource(SourceH) on the m_fileManager object. This likely triggers the file manager to scan the USB for media files and extract the necessary information about them.
This scanning action is crucial as it initiates the process of locating and indexing the media files present on the connected USB drive.
Additionally, in the init() method of MultimediaManager, there are other references and setups related to handling media sources, but the direct parsing of media files from USB primarily occurs when the USB device is connected, as highlighted above.
To find an entry point related to playing a song in the MultimediaManager code provided, we should look at methods that would typically handle playback actions.
One significant method related to playing a song is playItem(int index). Here are the key aspects of this method:
cpp
void MultimediaManager::playItem(int index)
{
const multimediamanager::MediaSources currentSource = m_sourceManager->GetCurrentSource();
if (m_sourceManager->IsStorageSource(currentSource) == true)
{
auto sourceHandler = m_sourceManager->GetMediaStorageSourceHandler(currentSource);
const int currentIndex = sourceHandler->GetCurrentMediaIndex();
// Check if index is valid considering our nowPlayingList
const auto& nowPList = sourceHandler->GetNowPlayingSongList();
if ((index < 0) || (nowPList.count() <= index))
{
qInfo() << "Index is invalid. NowP Count is" << nowPList.count() << "Index" << index;
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_STOPPED);
}
else
{
// Set LastUserPlaybackStatus
sourceHandler->SetLastUserPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_PLAYING);
qInfo() << "index: " << index << " currentIndex:" << currentIndex;
m_playerInterface->SetPlayingIndex(index);
m_playerInterface->SetPlaybackStatus(multimediamanager::PlaybackStatus_t::PB_PLAYING);
}
}
else if (m_sourceManager->IsBTSource(currentSource) == true)
{
m_bluetoothPlayer->SetPlayingIndex(index);
}
}
Breakdown of playItem(int index) Method
Get Current Source: It retrieves the current media source by calling m_sourceManager->GetCurrentSource().
Check Source Type: The method checks if the current source is a storage source.
Get Now Playing List: It acquires the list of currently playing songs (nowPList).
Index Validation: It validates the provided index against the size of the now-playing list. If the index is invalid, it stops playback.
Set Playback Status: If the index is valid, it updates the playback status using the m_playerInterface, indicating that a song is being played.
Further Steps
To proceed with understanding how a song is played, you can:
Check other related methods that may invoke playItem(int index), such as handling user input events or signals connecting to UI actions.
Investigate the Signal and Slot connections in the class that might also trigger playback actions.
Look into how m_playerInterface methods function and the overall audio system they integrate with, particularly how SetPlayingIndex and SetPlaybackStatus manage audio playback.
Other Related Methods
You might also be interested in the following methods:
nextMediaItem(int count): This method handles advancing to the next song in the playlist, which could lead to a call to the playItem.
previousMediaItem(int count): Similar purpose for the previous song.
Methods related to connecting signals to UI elements for play, pause, and skip functionalities.
By tracing these methods and examining their connections, you can gather a complete picture of how songs are initiated and managed during playback.