From fe614a983ba4254ff03b043ed16d30e2c2b154d8 Mon Sep 17 00:00:00 2001
From: Yann Boucher <yann.boucher@etu.utc.fr>
Date: Tue, 8 Jun 2021 14:56:09 +0200
Subject: [PATCH] Removed dependency to the multimedia module

---
 src/interface.cpp | 20 +++++++++++---------
 src/src.pro       |  2 +-
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/interface.cpp b/src/interface.cpp
index 2c8c170..99868c9 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -18,7 +18,7 @@
 #include <QTextStream>
 #include <QInputDialog>
 #include <QTimer>
-#include <QMediaPlayer>
+#include <QElapsedTimer>
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
@@ -637,11 +637,14 @@ void MainWindow::play_bad_apple()
     static QJsonArray bad_apple_frame_list;
     static QTimer bad_apple_timer;
     static bool bad_apple_connected;
-    static QMediaPlayer bad_apple_player;
+    static QElapsedTimer bad_apple_elapsed;
 
-    QFile f("bad_apple.json");
+    QFile f("extras/bad_apple.json");
     if (!f.open(QFile::ReadOnly | QFile::Text))
-        throw ModelLoadingException("Impossible de lire le fichier");
+    {
+        QMessageBox::warning(this, "", "Can't find 'extras/bad_apple.json'\n");
+        return;
+    }
     QTextStream in(&f);
 
     QJsonParseError parseError;
@@ -655,10 +658,8 @@ void MainWindow::play_bad_apple()
     {
         bad_apple_timer.callOnTimeout([this]
                                       {
-                                          if (bad_apple_player.mediaStatus() == QMediaPlayer::EndOfMedia)
-                                              return;
 
-                                          unsigned frame_idx = bad_apple_player.position()/(1000.f/30);
+                                          unsigned frame_idx = bad_apple_elapsed.elapsed()/(1000.f/30);
                                           if ((int)frame_idx >= bad_apple_frame_list.size())
                                           {
                                               bad_apple_timer.stop();
@@ -686,9 +687,10 @@ void MainWindow::play_bad_apple()
                                       });
     }
 
-    bad_apple_player.setMedia(QUrl::fromLocalFile("bad-apple.mp3"));
-    bad_apple_player.play();
+    //bad_apple_player.setMedia(QUrl::fromLocalFile("bad-apple.mp3"));
+    //bad_apple_player.play();
     ;
+    bad_apple_elapsed.start();
     bad_apple_timer.start(24);
     statusBar()->showMessage("Original : \"Bad Apple!!\" feat. Nomico by Alstroemeria Records", 60000);
 }
diff --git a/src/src.pro b/src/src.pro
index 213d27d..d80df89 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -1,4 +1,4 @@
-QT       += core gui multimedia
+QT       += core gui
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
-- 
GitLab