Kaynağa Gözat

moved to qmeidaplayer

master
Robin Thoni 9 yıl önce
ebeveyn
işleme
5cb095ba6d
4 değiştirilmiş dosya ile 16 ekleme ve 59 silme
  1. 0
    28
      mainwindow.cpp
  2. 0
    3
      mainwindow.h
  3. 7
    18
      radio.cpp
  4. 9
    10
      radio.h

+ 0
- 28
mainwindow.cpp Dosyayı Görüntüle

@@ -6,27 +6,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
6 6
 {
7 7
     ui->setupUi(this);
8 8
 
9
-    //avcodec_register_all();
10
-
11
-    QAudioFormat format;
12
-    format.setSampleRate(44100);
13
-    format.setChannelCount(2);
14
-    //format.setFrequency(48000);
15
-    //format.setChannels(2);
16
-    format.setSampleSize(128000);
17
-    format.setCodec("audio/pcm");
18
-    format.setByteOrder(QAudioFormat::LittleEndian);
19
-    format.setSampleType(QAudioFormat::SignedInt);
20
-
21
-    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
22
-    if (!info.isFormatSupported(format))
23
-        format = info.nearestFormat(format);
24
-
25
-    qDebug() << format;
26
-
27
-    output=new QAudioOutput(format, this);
28
-    out=output->start();
29
-
30 9
     currentRadio = 0;
31 10
     nrj = new NRJ(this);
32 11
     connect(nrj, SIGNAL(setupFinished()), this, SLOT(setupFinished()));
@@ -63,13 +42,6 @@ void MainWindow::radioChanged(Radio *r)
63 42
     currentRadio = r;
64 43
     if(currentRadio != 0)
65 44
     {
66
-        connect(currentRadio, SIGNAL(streamData(QByteArray)), this, SLOT(radioData(QByteArray)));
67 45
         currentRadio->startStream();
68 46
     }
69 47
 }
70
-
71
-void MainWindow::radioData(QByteArray data)
72
-{
73
-    out->write(data);
74
-    //streamData.append(data);
75
-}

+ 0
- 3
mainwindow.h Dosyayı Görüntüle

@@ -24,14 +24,11 @@ public:
24 24
 private slots:
25 25
     void setupFinished();
26 26
     void radioChanged(Radio* r);
27
-    void radioData(QByteArray data);
28 27
 
29 28
 private:
30 29
     Ui::MainWindow *ui;
31 30
     NRJ* nrj;
32 31
     Radio* currentRadio;
33
-    QAudioOutput* output;
34
-    QIODevice* out;
35 32
 
36 33
 };
37 34
 

+ 7
- 18
radio.cpp Dosyayı Görüntüle

@@ -10,10 +10,11 @@ Radio::Radio(QObject *parent) : QObject(parent), logo(0, 0)
10 10
     currentSong = 0;
11 11
     songsTries = 0;
12 12
     streamTries = 0;
13
-    stream = 0;
14 13
     songTimer = new QTimer(this);
15 14
     songTimer->setSingleShot(true);
16 15
     connect(songTimer, SIGNAL(timeout()), this, SLOT(songEnded()));
16
+    player = new QMediaPlayer(this);
17
+    player->setVolume(50);
17 18
 }
18 19
 
19 20
 QString Radio::getName()
@@ -61,11 +62,6 @@ Song *Radio::getCurrentSong()
61 62
     return currentSong;
62 63
 }
63 64
 
64
-QNetworkReply *Radio::getStream()
65
-{
66
-    return stream;
67
-}
68
-
69 65
 void Radio::setName(QString n)
70 66
 {
71 67
     name = n;
@@ -151,20 +147,13 @@ void Radio::startStream()
151 147
 {
152 148
     stopStream();
153 149
     streamTries = 0;
154
-    stream = mgr->get(QNetworkRequest(streamUrl));
155
-    stream->setReadBufferSize(128);
156
-    connect(stream, SIGNAL(readyRead()), this, SLOT(streamRead()));
157
-    emit streamChanged(stream);
150
+    player->setMedia(streamUrl);
151
+    player->play();
158 152
 }
159 153
 
160 154
 void Radio::stopStream()
161 155
 {
162
-    if(stream != 0)
163
-    {
164
-        stream->abort();
165
-        stream->deleteLater();
166
-        stream = 0;
167
-    }
156
+  player->stop();
168 157
 }
169 158
 
170 159
 void Radio::logoFinished()
@@ -214,7 +203,7 @@ void Radio::songsError(QNetworkReply::NetworkError)
214 203
     }
215 204
 }
216 205
 
217
-void Radio::streamRead()
206
+/*void Radio::streamRead()
218 207
 {
219 208
     if(stream->header(QNetworkRequest::LocationHeader).toUrl().isEmpty())
220 209
         emit streamData(stream->readAll());
@@ -224,7 +213,7 @@ void Radio::streamRead()
224 213
         stopStream();
225 214
         startStream();
226 215
     }
227
-}
216
+}*/
228 217
 
229 218
 void Radio::streamError()
230 219
 {

+ 9
- 10
radio.h Dosyayı Görüntüle

@@ -7,6 +7,7 @@
7 7
 #include <QPixmap>
8 8
 #include <QNetworkAccessManager>
9 9
 #include <QNetworkReply>
10
+#include <QMediaPlayer>
10 11
 #include <QList>
11 12
 #include <QTimer>
12 13
 #include "song.h"
@@ -27,18 +28,13 @@ public:
27 28
     QUrl getCoverBase();
28 29
 
29 30
     Song* getCurrentSong();
30
-    QNetworkReply* getStream();
31
-    
31
+
32 32
 signals:
33 33
     void logoDownloaded(QPixmap);
34 34
     void songChanged(Song*);
35 35
     void nextSongsUpdated();
36
-    void streamData(QByteArray);
37
-    void streamChanged(QNetworkReply*);
38
-    
39
-public slots:
40
-    void setNetworkManager(QNetworkAccessManager* m);
41 36
 
37
+public slots:
42 38
     void setName(QString n);
43 39
     void setClaim(QString c);
44 40
     void setTextColor(QColor c);
@@ -54,6 +50,9 @@ public slots:
54 50
     void startStream();
55 51
     void stopStream();
56 52
 
53
+public slots:
54
+    void setNetworkManager(QNetworkAccessManager* m);
55
+
57 56
 private slots:
58 57
     void logoFinished();
59 58
     void logoError(QNetworkReply::NetworkError);
@@ -61,7 +60,7 @@ private slots:
61 60
     void songsFinished();
62 61
     void songsError(QNetworkReply::NetworkError);
63 62
 
64
-    void streamRead();
63
+    //void streamRead();
65 64
     void streamError();
66 65
 
67 66
     void songEnded();
@@ -82,11 +81,11 @@ private:
82 81
     QTimer* songTimer;
83 82
 
84 83
     QNetworkAccessManager* mgr;
84
+    QMediaPlayer* player;
85 85
     int logoTries;
86 86
     int songsTries;
87 87
     int streamTries;
88
-    QNetworkReply* stream;
89
-    
88
+
90 89
 };
91 90
 
92 91
 #endif // RADIO_H

Loading…
İptal
Kaydet