this will break all functionality for now
[groove] / splayer.cpp
1 #include "splayer.h"
2 #include <QFile>
3 sPlayer::sPlayer(QObject *parent) :
4     QObject(parent)
5 {
6     manager = new QNetworkAccessManager();
7     buffer = new QBuffer();
8     audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
9     media = new Phonon::MediaObject(this);
10     Phonon::createPath(media, audioOutput);
11     playing = false;
12     //reply = new QNetworkReply();
13     internal = parent;
14     //buffer->open(QIODevice::ReadWrite);
15     connect(media,SIGNAL(finished()),this,SLOT(markComplete()));
16 }
17 void sPlayer::setPlaylist(playlist *playList)
18 {
19     this->pl = playList;
20     connect(pl,SIGNAL(bufferReady(int)),this,SLOT(start(int)));
21     connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(putb(int,qint64,qint64)));
22     //connect(pl,SIGNAL(downloadComplete(int)),this,SLOT(start(int)));
23
24 }
25 void sPlayer::markComplete()
26 {
27     pl->markPlayed(pl->currentplaying());
28     pl->setCurrentPlaying(-1);
29 }
30
31 sPlayer::~sPlayer()
32 {
33     manager->~QNetworkAccessManager();
34     //reply->~QIODevice();
35     media->~MediaNode();
36 }
37 void sPlayer::abortDownload()
38 {
39     //pd->hide();
40     //reply->abort();
41 }
42
43 void sPlayer::start(int p)
44 {
45     qDebug() << "got start play";
46     if(p == pl->currentplaying())
47         {
48             playing = true;
49             media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p)));
50             media->play();
51             qDebug() << "Playing";
52         }
53
54 }
55 void sPlayer::play()
56 {
57     if(pl->currentplaying() != -1)
58     {
59         //pl->setCurrentPlaying(pl->findFirstNotPlayed());
60     }
61     else
62         return;
63 }
64 void sPlayer::play(int p)
65 {
66     pl->setCurrentPlaying(p);
67     //pl->beginDownload(p);
68 }
69
70 void sPlayer::stop()
71 {
72     pl->setCurrentPlaying(-1);
73     media->stop();
74     playing = false;
75 }
76
77 void sPlayer::putb(int p, qint64 b, qint64 t)
78 {
79     //qDebug() << "Download: " << b << "Total: " << t;
80     if(p == pl->currentplaying())
81     {
82         if(pl->bReady(p))
83         {
84             StreamIO* stream = (StreamIO*) media->currentSource().stream();
85             stream->setStreamSize(pl->getBuffer(p)->size());
86         }
87     }
88 }