playlist: add basic m3u8 support
This commit is contained in:
@ -261,6 +261,15 @@ void MainWindow::dropEvent(QDropEvent *e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileName.endsWith(".m3u") || fileName.endsWith(".m3u8")) {
|
||||||
|
const QModelIndex & modelIndex = m_playlistManager->loadM3U8Playlist(urls.constFirst());
|
||||||
|
if (modelIndex.isValid()) {
|
||||||
|
loadByModelIndex(modelIndex);
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
|
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urls);
|
||||||
if (modelIndex.isValid()) {
|
if (modelIndex.isValid()) {
|
||||||
loadByModelIndex(modelIndex);
|
loadByModelIndex(modelIndex);
|
||||||
@ -292,9 +301,8 @@ void MainWindow::loadFile()
|
|||||||
urlList.append(QUrl::fromLocalFile(fileName));
|
urlList.append(QUrl::fromLocalFile(fileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_playlistManager->loadPlaylist(urlList);
|
const QModelIndex & modelIndex = m_playlistManager->loadPlaylist(urlList);
|
||||||
const QUrl & firstUrl = urlList.first();
|
loadByModelIndex(modelIndex);
|
||||||
loadFile(firstUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::loadFile(const QUrl &url)
|
void MainWindow::loadFile(const QUrl &url)
|
||||||
|
@ -186,6 +186,26 @@ QModelIndex PlaylistManager::loadPlaylist(const QUrl &url)
|
|||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QModelIndex PlaylistManager::loadM3U8Playlist(const QUrl &url)
|
||||||
|
{
|
||||||
|
QFile file(url.toLocalFile());
|
||||||
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QList<QUrl> urls;
|
||||||
|
while (!file.atEnd()) {
|
||||||
|
QString line = file.readLine();
|
||||||
|
if (line.startsWith('#')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QFileInfo fileInfo(file);
|
||||||
|
QUrl item = QUrl::fromUserInput(line, fileInfo.absolutePath());
|
||||||
|
urls.append(item);
|
||||||
|
}
|
||||||
|
return loadPlaylist(urls);
|
||||||
|
} else {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int PlaylistManager::totalCount() const
|
int PlaylistManager::totalCount() const
|
||||||
{
|
{
|
||||||
return m_model.rowCount();
|
return m_model.rowCount();
|
||||||
@ -196,7 +216,7 @@ QModelIndex PlaylistManager::previousIndex() const
|
|||||||
int count = totalCount();
|
int count = totalCount();
|
||||||
if (count == 0) return {};
|
if (count == 0) return {};
|
||||||
|
|
||||||
return m_model.index(m_currentIndex - 1 < 0 ? count - 1 : m_currentIndex - 1);
|
return m_model.index(isFirstIndex() ? count - 1 : m_currentIndex - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex PlaylistManager::nextIndex() const
|
QModelIndex PlaylistManager::nextIndex() const
|
||||||
@ -204,7 +224,7 @@ QModelIndex PlaylistManager::nextIndex() const
|
|||||||
int count = totalCount();
|
int count = totalCount();
|
||||||
if (count == 0) return {};
|
if (count == 0) return {};
|
||||||
|
|
||||||
return m_model.index(m_currentIndex + 1 == count ? 0 : m_currentIndex + 1);
|
return m_model.index(isLastIndex() ? 0 : m_currentIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex PlaylistManager::curIndex() const
|
QModelIndex PlaylistManager::curIndex() const
|
||||||
@ -212,6 +232,16 @@ QModelIndex PlaylistManager::curIndex() const
|
|||||||
return m_model.index(m_currentIndex);
|
return m_model.index(m_currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlaylistManager::isFirstIndex() const
|
||||||
|
{
|
||||||
|
return m_currentIndex == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PlaylistManager::isLastIndex() const
|
||||||
|
{
|
||||||
|
return m_currentIndex + 1 == totalCount();
|
||||||
|
}
|
||||||
|
|
||||||
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
|
void PlaylistManager::setCurrentIndex(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
|
if (index.isValid() && index.row() >= 0 && index.row() < totalCount()) {
|
||||||
|
@ -61,11 +61,14 @@ public:
|
|||||||
void setPlaylist(const QList<QUrl> & url);
|
void setPlaylist(const QList<QUrl> & url);
|
||||||
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
Q_INVOKABLE QModelIndex loadPlaylist(const QList<QUrl> & urls);
|
||||||
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
|
Q_INVOKABLE QModelIndex loadPlaylist(const QUrl & url);
|
||||||
|
Q_INVOKABLE QModelIndex loadM3U8Playlist(const QUrl & url);
|
||||||
|
|
||||||
int totalCount() const;
|
int totalCount() const;
|
||||||
QModelIndex previousIndex() const;
|
QModelIndex previousIndex() const;
|
||||||
QModelIndex nextIndex() const;
|
QModelIndex nextIndex() const;
|
||||||
QModelIndex curIndex() const;
|
QModelIndex curIndex() const;
|
||||||
|
bool isFirstIndex() const;
|
||||||
|
bool isLastIndex() const;
|
||||||
void setCurrentIndex(const QModelIndex & index);
|
void setCurrentIndex(const QModelIndex & index);
|
||||||
QUrl urlByIndex(const QModelIndex & index);
|
QUrl urlByIndex(const QModelIndex & index);
|
||||||
QString localFileByIndex(const QModelIndex & index);
|
QString localFileByIndex(const QModelIndex & index);
|
||||||
|
Reference in New Issue
Block a user