3 sPlayer::sPlayer(QObject *parent) :
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);
12 //reply = new QNetworkReply();
14 //buffer->open(QIODevice::ReadWrite);
15 connect(media,SIGNAL(finished()),this,SLOT(markComplete()));
17 void sPlayer::setPlaylist(playlist *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)));
25 void sPlayer::markComplete()
27 pl->markPlayed(pl->currentplaying());
28 if(pl->existAt(pl->currentplaying()+1))
30 pl->setCurrentPlaying(pl->currentplaying()+1);
31 if(pl->bReady(pl->currentplaying()))
32 this->start(pl->currentplaying());
35 pl->setCurrentPlaying(-1);
39 if(media->state() == Phonon::PausedState)
41 if(media->state() == Phonon::PlayingState)
44 void sPlayer::playNext()
46 if(pl->existAt(pl->currentplaying()+1))
55 manager->~QNetworkAccessManager();
56 //reply->~QIODevice();
62 if(pl->existAt(pl->currentplaying()-1))
64 pl->setCurrentPlaying(pl->currentplaying()-1);
65 if(pl->bReady(pl->currentplaying()))
66 this->start(pl->currentplaying());
69 pl->setCurrentPlaying(-1);
72 void sPlayer::abortDownload()
78 void sPlayer::start(int p)
80 qDebug() << "got start play";
81 if(p == pl->currentplaying())
84 media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p)));
86 qDebug() << "Playing";
92 if(pl->currentplaying() != -1)
94 //pl->setCurrentPlaying(pl->findFirstNotPlayed());
99 void sPlayer::play(int p)
101 if(pl->currentplaying() != -1)
102 pl->freeMemory(pl->currentplaying());
103 pl->setCurrentPlaying(p);
104 //pl->beginDownload(p);
111 if(pl->currentplaying() != -1)
112 pl->markPlayed(pl->currentplaying());
113 pl->setCurrentPlaying(-1);
117 void sPlayer::putb(int p, qint64 b, qint64 t)
119 //qDebug() << "Download: " << b << "Total: " << t;
120 if(p == pl->currentplaying())
124 StreamIO* stream = (StreamIO*) media->currentSource().stream();
125 stream->setStreamSize(pl->getBuffer(p)->size());