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()));
16 media->setTickInterval(200);
17 connect(media,SIGNAL(tick(qint64)),this,SLOT(updatePlayPosition(qint64)));
19 void sPlayer::setPlaylist(playlist *playList)
22 connect(pl,SIGNAL(bufferReady(int)),this,SLOT(start(int)));
23 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(putb(int,qint64,qint64)));
24 //connect(pl,SIGNAL(downloadComplete(int)),this,SLOT(start(int)));
27 void sPlayer::markComplete()
29 pl->markPlayed(pl->currentplaying());
30 if(pl->existAt(pl->currentplaying()+1))
32 pl->setCurrentPlaying(pl->currentplaying()+1);
33 if(pl->bReady(pl->currentplaying()))
34 this->start(pl->currentplaying());
37 pl->setCurrentPlaying(-1);
39 void sPlayer::updatePlayPosition(qint64 time)
41 //qDebug() << time << ":" << media->totalTime();
46 if(media->state() == Phonon::PausedState)
48 if(media->state() == Phonon::PlayingState)
51 void sPlayer::playNext()
53 if(pl->existAt(pl->currentplaying()+1))
62 manager->~QNetworkAccessManager();
63 //reply->~QIODevice();
69 if(pl->existAt(pl->currentplaying()-1))
71 pl->setCurrentPlaying(pl->currentplaying()-1);
72 if(pl->bReady(pl->currentplaying()))
73 this->start(pl->currentplaying());
76 pl->setCurrentPlaying(-1);
79 void sPlayer::abortDownload()
85 void sPlayer::start(int p)
87 qDebug() << "got start play";
88 if(p == pl->currentplaying())
91 media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p)));
93 qDebug() << "Playing";
99 if(pl->currentplaying() != -1)
101 //pl->setCurrentPlaying(pl->findFirstNotPlayed());
106 void sPlayer::play(int p)
108 if(pl->currentplaying() != -1)
109 pl->freeMemory(pl->currentplaying());
110 pl->setCurrentPlaying(p);
111 //pl->beginDownload(p);
118 if(pl->currentplaying() != -1)
119 pl->markPlayed(pl->currentplaying());
120 pl->setCurrentPlaying(-1);
124 void sPlayer::putb(int p, qint64 b, qint64 t)
126 //qDebug() << "Download: " << b << "Total: " << t;
127 if(p == pl->currentplaying())
131 StreamIO* stream = (StreamIO*) media->currentSource().stream();
132 stream->setStreamSize(pl->getBuffer(p)->size());