android support

This commit is contained in:
Andrei Yankovich 2017-12-13 22:40:29 +03:00
parent 2f0b649f52
commit 4596678321
9 changed files with 92 additions and 14 deletions

View File

@ -32,7 +32,8 @@ SOURCES += \
../sync/song.cpp \
../sync/sync.cpp \
servermodel.cpp \
songmodel.cpp
songmodel.cpp \
../sync/player.cpp
HEADERS += \
mainwindow.h \
@ -44,7 +45,8 @@ HEADERS += \
../sync/song.h \
../sync/sync.h \
servermodel.h \
songmodel.h
songmodel.h \
../sync/player.h
FORMS += \
mainwindow.ui

View File

@ -9,6 +9,7 @@
// sqlite config
#define DATABASE_NAME "songdata.dat"
#define DATATABLE_NAME "songs"
#define BUFFER_NAME "buffer"
// network config
#define DEFAULT_ADRESS "DEFAULT_ADRESS"

View File

@ -67,8 +67,9 @@ class InitDBError:public std::exception
{
public:
QString what(){
return QObject::tr("Error creating database..");
return QObject::tr("Error creating database.");
}
};
#endif // EXAPTIONS_H

39
sync/player.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "player.h"
#include <stdio.h>
#include "exaptions.h"
#include <QFile>
#include <QDir>
Player::Player(const QString bufferFile)
{
buffer = bufferFile;
}
Player::Player(const QString bufferFile, QObject *parent, Flags flags):
QMediaPlayer(parent, flags)
{
buffer = bufferFile;
}
bool Player::setMediaFromBytes(const QByteArray &array){
QFile f(buffer);
if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate)){
return false;
}
if(array.length() != f.write(array.data(),array.length())){
f.close();
return false;
}
f.close();
setMedia(QUrl::fromLocalFile(QDir("./").absoluteFilePath(buffer)));
return true;
}
Player::~Player(){
}

20
sync/player.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef PLAYER_H
#define PLAYER_H
#include <QMediaPlayer>
class Player : public QMediaPlayer
{
Q_OBJECT
private:
QString buffer;
public:
Player(const QString bufferFile);
Player(const QString bufferFile, QObject *parent = Q_NULLPTR, Flags flags = Flags());
bool setMediaFromBytes(const QByteArray& array);
~Player();
};
#endif // PLAYER_H

View File

@ -23,7 +23,7 @@ Sync::Sync(const QString address, int port, const QString &datadir):
{
node = new Node(address , this->port = port);
player = new QMediaPlayer(nullptr,QMediaPlayer::LowLatency);
player = new Player(BUFFER_NAME,nullptr,QMediaPlayer::LowLatency);
buffer = new QBuffer;
if(!player->isAvailable()){
throw MediaException();
@ -223,10 +223,9 @@ bool Sync::play(const Song &song, const Syncer *syncdata){
return false;
}
buffer->close();
buffer->setData(song.source);
buffer->open(QIODevice::ReadOnly);
player->setMedia(QMediaContent(), buffer);
if(!player->setMediaFromBytes(song.source)){
return false;
}
fbroadcaster = !bool(syncdata);
if(!findHeader(song) && save(song) > -1 && !findHeader(song)){

View File

@ -6,7 +6,7 @@
#include <chrono>
#include "config.h"
#include <QMediaPlayer>
#include "player.h"
class QSqlDatabase;
class QSqlQuery;
@ -27,7 +27,7 @@ class Sync : public QObject
private:
Node *node;
QSqlDatabase *db;
QMediaPlayer *player;
Player *player;
QBuffer *buffer;
QList<SongHeader> playList;
SongHeader * curentSong;

View File

@ -28,7 +28,13 @@ SOURCES += \
song.cpp \
node.cpp \
ETcpSocket.cpp \
LocalScanner.cpp
LocalScanner.cpp \
ETcpSocket.cpp \
LocalScanner.cpp \
node.cpp \
player.cpp \
song.cpp \
sync.cpp
HEADERS += \
sync.h \
@ -37,7 +43,15 @@ HEADERS += \
config.h \
exaptions.h \
ETcpSocket.h \
LocalScanner.h
LocalScanner.h \
config.h \
ETcpSocket.h \
exaptions.h \
LocalScanner.h \
node.h \
player.h \
song.h \
sync.h
unix {
target.path = /usr/lib
INSTALLS += target

View File

@ -11,7 +11,8 @@ SOURCES += tst_synctest.cpp \
../LocalScanner.cpp \
../node.cpp \
../song.cpp \
../sync.cpp
../sync.cpp \
../player.cpp
RESOURCES += \
res.qrc
@ -23,4 +24,5 @@ HEADERS += \
../LocalScanner.h \
../node.h \
../song.h \
../sync.h
../sync.h \
../player.h