[PATCH] Video and audio from different sources

Forum to talk about the development of SMPlayer (code, patches...).

[PATCH] Video and audio from different sources

Postby capt.d. » Sun Dec 11, 2016 10:36 pm

Aloha

It enables to play video and audio from different files and/or urls. It's comes with my previous patch. I moved loadpage.[h,cpp] files from youtube folder to src. Disabling youtube support, makes playlist uncompilable.

Code: Select all
--- basegui.cpp   2016-10-11 23:00:24.000000000 +0200
+++ basegui.cpp.new   2016-12-11 14:13:22.000000000 +0100
@@ -70,6 +70,7 @@
 #include "errordialog.h"
 #include "timedialog.h"
 #include "stereo3ddialog.h"
+#include "selectseparateddialog.h"
 
 #ifdef BOOKMARKS
 #include "inputbookmark.h"
@@ -387,6 +388,10 @@
    connect( openFileAct, SIGNAL(triggered()),
              this, SLOT(openFile()) );
 
+        openSeparatedAct = new MyAction( this, "open_separated");
+        connect( openSeparatedAct, SIGNAL(triggered()),
+        this, SLOT(openSeparated()) );
+
    openDirectoryAct = new MyAction( this, "open_directory" );
    connect( openDirectoryAct, SIGNAL(triggered()),
              this, SLOT(openDirectory()) );
@@ -431,8 +436,8 @@
 
    clearRecentsAct = new MyAction( this, "clear_recents" );
    connect( clearRecentsAct, SIGNAL(triggered()), this, SLOT(clearRecentsList()) );
-
-   // Favorites
+   
+        // Favorites
    favorites = new Favorites(Paths::configPath() + "/favorites.m3u8", this);
    favorites->menuAction()->setObjectName( "favorites_menu" );
    addAction(favorites->editAct());
@@ -1650,6 +1655,7 @@
 
    // Menu File
    openFileAct->change( Images::icon("open"), tr("&File...") );
+   openSeparatedAct->change( Images::icon("open"), tr("Open separated files") );
    openDirectoryAct->change( Images::icon("openfolder"), tr("D&irectory...") );
    openPlaylistAct->change( Images::icon("open_playlist"), tr("&Playlist...") );
    openVCDAct->change( Images::icon("vcd"), tr("V&CD") );
@@ -1941,7 +1947,7 @@
    recentfiles_menu->menuAction()->setText( tr("&Recent files") );
    recentfiles_menu->menuAction()->setIcon( Images::icon("recents") );
    clearRecentsAct->change( Images::icon("delete"), tr("&Clear") );
-
+   
    disc_menu->menuAction()->setText( tr("&Disc") );
    disc_menu->menuAction()->setIcon( Images::icon("open_disc") );
 
@@ -2496,7 +2502,7 @@
    // Recents submenu
    recentfiles_menu = new QMenu(this);
    recentfiles_menu->menuAction()->setObjectName("recents_menu");
-
+   
    // Disc submenu
    disc_menu = new QMenu(this);
    disc_menu->menuAction()->setObjectName("disc_menu");
@@ -2769,7 +2775,8 @@
 
    // OPEN MENU
    openMenu->addAction(openFileAct);
-   openMenu->addMenu(recentfiles_menu);
+   openMenu->addAction(openSeparatedAct);
+        openMenu->addMenu(recentfiles_menu);
    openMenu->addMenu(favorites);
    openMenu->addAction(openDirectoryAct);
    openMenu->addAction(openPlaylistAct);
@@ -4097,6 +4104,19 @@
    }
 }
 
+void BaseGui::openSeparated() {
+   qDebug("BaseGui::openSeparated");
+
+   exitFullscreenIfNeeded();
+   SelectSeparatedDialog okno(pref->latest_dir, this);
+   if(okno.exec() == QDialog::Accepted)
+   {
+      core->mset.external_audio = okno.getAudio();
+      openFile(okno.getVideo());
+   }
+
+}
+
 void BaseGui::openFavorite(QString file) {
    qDebug("BaseGui::openFavorite");
 

Code: Select all
--- basegui.h   2016-07-17 11:06:26.000000000 +0200
+++ basegui.h.new   2016-12-09 11:41:59.000000000 +0100
@@ -105,6 +105,7 @@
    virtual void openFile();
    virtual void openFile(QString file);
    virtual void openFiles(QStringList files);
+        virtual void openSeparated();
    virtual void openFavorite(QString file);
    virtual void openURL();
    virtual void openURL(QString url);
@@ -436,6 +437,7 @@
 
    // Menu File
    MyAction * openFileAct;
+        MyAction * openSeparatedAct;
    MyAction * openDirectoryAct;
    MyAction * openPlaylistAct;
    MyAction * openVCDAct;

Code: Select all
--- playlist.cpp   2016-12-11 16:04:59.000000000 +0100
+++ playlist.cpp.new   2016-12-11 16:06:58.000000000 +0100
@@ -63,7 +63,7 @@
 
 #ifdef PLAYLIST_DOWNLOAD
 #include "inputurl.h"
-#include "youtube/loadpage.h"
+#include "loadpage.h"
 #include "urlhistory.h"
 #include <QNetworkAccessManager>
 #include <QTemporaryFile>
@@ -76,8 +76,7 @@
 #endif
 
 #define DRAG_ITEMS 0
-#define PL_ALLOW_DUPLICATES 1
-#define SIMULATE_FILE_DELETION 0
+#define PL_ALLOW_DUPLICATES 1w#define SIMULATE_FILE_DELETION 0
 #define USE_ITEM_DELEGATE 0
 
 #define COL_NUM 0
@@ -119,6 +118,7 @@
    setDuration(0);
    setPlayed(false);
    setCurrent(false);
+        setPrevPlayed(false);
 
    col_num->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
 }
@@ -133,6 +133,7 @@
    setDuration(duration);
    setPlayed(false);
    setCurrent(false);
+        setPrevPlayed(false);
 
    col_num->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
 }
@@ -193,6 +194,10 @@
 #endif
 }
 
+void PLItem::setPrevPlayed(bool b) {
+        setData(b, Role_PrevPlayed);
+}
+
 QString PLItem::filename() {
    return col_filename->data().toString();
 }
@@ -217,6 +222,10 @@
    return data(Role_Current).toBool();
 }
 
+bool PLItem::isPrevPlayed() {
+        return data(Role_PrevPlayed).toBool();
+}
+
 QList<QStandardItem *> PLItem::items() {
    QList<QStandardItem *> l;
    l << col_num << this << col_duration << col_filename;
@@ -285,7 +294,7 @@
    QTime now = QTime::currentTime();
    qsrand(now.msec());
 
-   loadSettings();
+   //loadSettings();
 
    // Save config every 5 minutes.
    save_timer = new QTimer(this);
@@ -752,6 +761,16 @@
    return -1;
 }
 
+int Playlist::findPrevPlayed() {
+   int rc = proxy->rowCount();
+        for (int i = 0; i < rc; i++) {
+           if (itemFromProxy(i)->isPrevPlayed()) {
+                                return i;
+                }
+       }
+       return -1;
+}
+
 void Playlist::clear() {
    table->setRowCount(0);
    setCurrentItem(0);
@@ -1358,6 +1377,14 @@
 
    QString filename = itemFromProxy(n)->filename();
    if (!filename.isEmpty()) {
+      int prev = findPrevPlayed();
+      if (prev > -1) {
+         itemFromProxy(prev)->setPrevPlayed(false);
+      }
+      int current = findCurrentItem();
+      if (current > -1) {
+         itemFromProxy(current)->setPrevPlayed(true);
+      }
       setCurrentItem(n);
       if (play_files_from_start) {
          emit requestToPlayFile(filename, 0);
@@ -1397,12 +1424,21 @@
 
 void Playlist::playPrev() {
    qDebug("Playlist::playPrev");
-   int current = findCurrentItem() - 1;
-   if (current >= 0) {
-      playItem(current);
-   } else {
-      if (proxy->rowCount() > 1) playItem(proxy->rowCount() - 1);
-   }
+   int current = findCurrentItem();
+        if (shuffleAct->isChecked()) {
+      int prev = findPrevPlayed();
+                if (prev > -1) {
+                      itemFromProxy(prev)->setPrevPlayed(false);
+                      playItem(prev);
+                }
+        } else {
+                current--;
+           if (current >= 0) {
+            playItem(current);
+           } else {
+            if (proxy->rowCount() > 1) playItem(proxy->rowCount() - 1);
+           }
+      }
 }
 
 void Playlist::playNextAuto() {
@@ -1945,7 +1981,7 @@
    set->setValue( "filter", filter_edit->text() );
    set->setValue( "sort_case_sensitive", sortCaseSensitive() );
    set->setValue( "auto_sort", autoSort() );
-        set->setValue( "current_item", findCurrentItem() );
+
    set->setValue( "show_search", showSearchAct->isChecked() );
 
    set->endGroup();
@@ -2020,7 +2056,6 @@
    QString filter = set->value( "filter").toString();
    bool sort_case_sensitive = set->value("sort_case_sensitive", false).toBool();
    bool auto_sort = set->value("auto_sort", false).toBool();
-        setCurrentItem( set->value( "current_item", -1 ).toInt() );
 
    showSearchAct->setChecked( set->value( "show_search", false).toBool() );
 

Code: Select all
--- playlist.h  2016-12-11 16:07:51.000000000 +0100
+++ playlist.h.new      2016-11-29 19:34:18.000000000 +0100
@@ -32,7 +32,7 @@

 class PLItem : public QStandardItem {
 public:
-        enum PLItem_Roles { Role_Played = Qt::UserRole + 2, Role_Current = Qt::UserRole + 3 };
+        enum PLItem_Roles { Role_Played = Qt::UserRole + 2, Role_Current = Qt::UserRole + 3, Role_PrevPlayed = Qt::UserRole + 4 };

        PLItem();
        PLItem(const QString filename, const QString name, double duration);
@@ -44,6 +44,7 @@
        void setPlayed(bool played);
        void setPosition(int position);
        void setCurrent(bool b);
+        void setPrevPlayed(bool b);

        QString filename();
        QString name();
@@ -51,6 +52,7 @@
        bool played();
        int position();
        bool isCurrent();
+        bool isPrevPlayed();

        QList<QStandardItem *> items();

@@ -217,6 +219,7 @@
        int findCurrentItem();
        void clearPlayedTag();
        int chooseRandomItem();
+       int findPrevPlayed();
        QString lastDir();

        void setPlaylistFilename(const QString &);

Code: Select all
--- smplayer.pro   2016-10-01 22:51:55.000000000 +0200
+++ smplayer.pro.new   2016-12-11 16:33:31.000000000 +0100
@@ -38,7 +38,7 @@
 
 # Whether to include support for the obsolete mplayer2 or not
 # (requires MPLAYER_SUPPORT)
-DEFINES += MPLAYER2_SUPPORT
+#DEFINES += MPLAYER2_SUPPORT
 
 # Note to distro maintainers:
 # By disabling SHARE_ACTIONS or SHARE_WIDGET
@@ -55,7 +55,7 @@
    DEFINES += HDPI_SUPPORT
 }
 
-#DEFINES += SIMPLE_BUILD
+DEFINES += SIMPLE_BUILD
 #DEFINES += IDOPT_BUILD
 
 contains( DEFINES, SIMPLE_BUILD ) {
@@ -230,7 +230,9 @@
    clhelp.h \
    cleanconfig.h \
    smplayer.h \
-   myapplication.h
+   myapplication.h \
+   loadpage.h \
+   selectseparateddialog.h
 
 
 SOURCES   += version.cpp \
@@ -328,6 +330,8 @@
    cleanconfig.cpp \
    smplayer.cpp \
    myapplication.cpp \
+   selectseparateddialog.cpp \
+   loadpage.cpp \
    main.cpp
 
 FORMS = inputdvddirectory.ui logwindow.ui infowindow.ui filepropertiesdialog.ui \
@@ -336,7 +340,7 @@
         prefperformance.ui prefinput.ui prefsubtitles.ui prefadvanced.ui \
         prefplaylist.ui prefupdates.ui prefnetwork.ui favoriteeditor.ui \
         about.ui inputmplayerversion.ui errordialog.ui timedialog.ui stereo3ddialog.ui \
-        toolbareditor.ui multilineinputdialog.ui
+        toolbareditor.ui multilineinputdialog.ui selectseparateddialog.ui
 
 contains( DEFINES, TV_SUPPORT ) {
    HEADERS += tvlist.h preftv.h tvsettings.h
@@ -429,8 +433,8 @@
    INCLUDEPATH += youtube
    DEPENDPATH += youtube
 
-   HEADERS += youtube/retrieveyoutubeurl.h youtube/loadpage.h
-   SOURCES += youtube/retrieveyoutubeurl.cpp youtube/loadpage.cpp
+   HEADERS += youtube/retrieveyoutubeurl.h
+   SOURCES += youtube/retrieveyoutubeurl.cpp
 
    contains( DEFINES, YT_USE_SCRIPT ) {
       DEFINES += YT_USE_SIG


selectseparateddialog.h:
Code: Select all
#ifndef SEPARATEDDIALOG_H
#define SEPARATEDDIALOG_H

#include "ui_selectseparateddialog.h"
#include <QDialog>

class  SelectSeparatedDialog : public QDialog, public Ui::SelectSeparatedDialog
{
   Q_OBJECT
public:
   SelectSeparatedDialog(QString& latestdir, QWidget* parent = 0, Qt::WindowFlags f = 0 );
   ~SelectSeparatedDialog();

   QString getVideo();
        QString getAudio();

private:
   QString& latestdir;

private  slots :
   void videoURLB_released();
   void videoFileB_released();
   void audioURLB_released();
   void audioFileB_released();

};

#endif


selectseparateddialog.cpp
Code: Select all
#include <QClipboard>
#include "extensions.h"
#include "inputurl.h"
#include "filedialog.h"
#include "selectseparateddialog.h"


SelectSeparatedDialog::SelectSeparatedDialog(QString& _latestdir, QWidget* parent, Qt::WindowFlags f )
   : QDialog(parent, f), latestdir(_latestdir)
{
   setupUi(this);
   buttonBox->buttons().first()->setEnabled(false);
   connect (videoURLB, SIGNAL(released()), this, SLOT (videoURLB_released()));
   connect (videoFileB, SIGNAL(released()), this, SLOT (videoFileB_released()));
   connect (audioURLB, SIGNAL(released()), this, SLOT (audioURLB_released()));
   connect (audioFileB, SIGNAL(released()), this, SLOT (audioFileB_released()));
}

SelectSeparatedDialog::~SelectSeparatedDialog() {
}


QString SelectSeparatedDialog::getVideo() {
   return video->text();
}

QString SelectSeparatedDialog::getAudio() {
   return audio->text();
}

void SelectSeparatedDialog::videoURLB_released() {
   InputURL u(this);
   QString clipboard(QApplication::clipboard()->text());
   if ((!clipboard.isEmpty()) && (clipboard.contains("://")) ) {
      u.setURL(clipboard);
   }
   if (u.exec() == QDialog::Accepted)
   {
      QString s(u.url());
      if (!s.isEmpty())
         video->setText(s);
   }
   buttonBox->buttons().first()->setEnabled(!(video->text().isEmpty() || audio->text().isEmpty()));
}

void SelectSeparatedDialog::videoFileB_released() {
   Extensions e;
       QString s = MyFileDialog::getOpenFileName(
                       this, tr("Choose a file"), latestdir,
                       tr("Video") + e.video().forFilter());

       if ( !s.isEmpty() )
       {
      video->setText(s);   
   }
   buttonBox->buttons().first()->setEnabled(!(video->text().isEmpty() || audio->text().isEmpty()));

}

void SelectSeparatedDialog::audioURLB_released() {
   InputURL u(this);
   QString clipboard(QApplication::clipboard()->text())
   ;if ((!clipboard.isEmpty()) && (clipboard.contains("://")) ) {
      u.setURL(clipboard);
   }
   if (u.exec() == QDialog::Accepted)
   {
      QString s(u.url());
      if (!s.isEmpty())
         audio->setText(s);
   }
   buttonBox->buttons().first()->setEnabled(!(video->text().isEmpty() || audio->text().isEmpty()));
}

void SelectSeparatedDialog::audioFileB_released() {
   Extensions e;
       QString s = MyFileDialog::getOpenFileName(
                       this, tr("Choose a file"), latestdir,
                       tr("Audio") + e.audio().forFilter());

       if (!s.isEmpty() )
       {
      audio->setText(s);   
   }
   buttonBox->buttons().first()->setEnabled(!(video->text().isEmpty() || audio->text().isEmpty()));
}

#include "moc_selectseparateddialog.cpp"


selectseparateddialog.ui
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>SelectSeparatedDialog</class>
 <widget class="QDialog" name="SelectSeparatedDialog">
  <property name="windowModality">
   <enum>Qt::NonModal</enum>
  </property>
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>810</width>
    <height>163</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="windowTitle">
   <string>Select video and audio sources</string>
  </property>
  <property name="accessibleName">
   <string/>
  </property>
  <property name="accessibleDescription">
   <string/>
  </property>
  <widget class="QDialogButtonBox" name="buttonBox">
   <property name="enabled">
    <bool>true</bool>
   </property>
   <property name="geometry">
    <rect>
     <x>460</x>
     <y>130</y>
     <width>341</width>
     <height>32</height>
    </rect>
   </property>
   <property name="orientation">
    <enum>Qt::Horizontal</enum>
   </property>
   <property name="standardButtons">
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
   </property>
  </widget>
  <widget class="QWidget" name="verticalLayoutWidget_3">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>10</y>
     <width>791</width>
     <height>101</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_4">
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout">
      <item>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item alignment="Qt::AlignTop">
         <widget class="QLabel" name="label">
          <property name="maximumSize">
           <size>
            <width>607</width>
            <height>16777215</height>
           </size>
          </property>
          <property name="text">
           <string>Video file:</string>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QLineEdit" name="video">
          <property name="enabled">
           <bool>false</bool>
          </property>
          <property name="focusPolicy">
           <enum>Qt::NoFocus</enum>
          </property>
          <property name="contextMenuPolicy">
           <enum>Qt::NoContextMenu</enum>
          </property>
          <property name="acceptDrops">
           <bool>false</bool>
          </property>
         </widget>
        </item>
       </layout>
      </item>
      <item alignment="Qt::AlignBottom">
       <widget class="QPushButton" name="videoFileB">
        <property name="text">
         <string>File</string>
        </property>
       </widget>
      </item>
      <item alignment="Qt::AlignBottom">
       <widget class="QPushButton" name="videoURLB">
        <property name="text">
         <string>URL</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
    <item>
     <layout class="QHBoxLayout" name="horizontalLayout_2">
      <item>
       <layout class="QVBoxLayout" name="verticalLayout_3">
        <item alignment="Qt::AlignTop">
         <widget class="QLabel" name="label_2">
          <property name="maximumSize">
           <size>
            <width>603</width>
            <height>16777215</height>
           </size>
          </property>
          <property name="text">
           <string>Audio file:</string>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QLineEdit" name="audio">
          <property name="enabled">
           <bool>false</bool>
          </property>
          <property name="focusPolicy">
           <enum>Qt::NoFocus</enum>
          </property>
          <property name="contextMenuPolicy">
           <enum>Qt::NoContextMenu</enum>
          </property>
          <property name="acceptDrops">
           <bool>false</bool>
          </property>
         </widget>
        </item>
       </layout>
      </item>
      <item alignment="Qt::AlignBottom">
       <widget class="QPushButton" name="audioFileB">
        <property name="text">
         <string>File</string>
        </property>
       </widget>
      </item>
      <item alignment="Qt::AlignBottom">
       <widget class="QPushButton" name="audioURLB">
        <property name="text">
         <string>URL</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
   </layout>
  </widget>
  <widget class="Line" name="line">
   <property name="geometry">
    <rect>
     <x>10</x>
     <y>120</y>
     <width>781</width>
     <height>16</height>
    </rect>
   </property>
   <property name="orientation">
    <enum>Qt::Horizontal</enum>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections>
  <connection>
   <sender>buttonBox</sender>
   <signal>accepted()</signal>
   <receiver>SelectSeparatedDialog</receiver>
   <slot>accept()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>248</x>
     <y>254</y>
    </hint>
    <hint type="destinationlabel">
     <x>157</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>buttonBox</sender>
   <signal>rejected()</signal>
   <receiver>SelectSeparatedDialog</receiver>
   <slot>reject()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>316</x>
     <y>260</y>
    </hint>
    <hint type="destinationlabel">
     <x>286</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>


----
Live long and prosper.
capt.d.
capt.d.
 
Posts: 9
Joined: Sun Dec 08, 2013 7:02 pm

Return to Development

Who is online

Users browsing this forum: Google [Bot] and 1 guest