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();
59 void sPlayer::abortDownload()
65 void sPlayer::start(int p)
67 qDebug() << "got start play";
68 if(p == pl->currentplaying())
71 media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p)));
73 qDebug() << "Playing";
79 if(pl->currentplaying() != -1)
81 //pl->setCurrentPlaying(pl->findFirstNotPlayed());
86 void sPlayer::play(int p)
88 if(pl->currentplaying() != -1)
89 pl->freeMemory(pl->currentplaying());
90 pl->setCurrentPlaying(p);
91 //pl->beginDownload(p);
98 if(pl->currentplaying() != -1)
99 pl->markPlayed(pl->currentplaying());
100 pl->setCurrentPlaying(-1);
104 void sPlayer::putb(int p, qint64 b, qint64 t)
106 //qDebug() << "Download: " << b << "Total: " << t;
107 if(p == pl->currentplaying())
111 StreamIO* stream = (StreamIO*) media->currentSource().stream();
112 stream->setStreamSize(pl->getBuffer(p)->size());