Skip to content

Commit

Permalink
sound reading test
Browse files Browse the repository at this point in the history
  • Loading branch information
remjey committed Jul 23, 2020
1 parent 96ad6e6 commit 890100a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 7 deletions.
3 changes: 3 additions & 0 deletions harbour-gopherette.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ TARGET = harbour-gopherette

CONFIG += sailfishapp

QT += multimedia

SOURCES += src/harbour-gopherette.cpp \
src/customnetworkaccessmanagerfactory.cpp \
src/customreply.cpp \
Expand Down Expand Up @@ -51,6 +53,7 @@ HEADERS += \
src/requester.h

DISTFILES += \
qml/components/AudioPlayer.qml \
qml/components/ImageDisplay.qml \
qml/components/PageStackEvents.qml \
qml/pages/Browser.qml \
Expand Down
26 changes: 26 additions & 0 deletions qml/components/AudioPlayer.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import QtQuick 2.0
import QtMultimedia 5.0

import Sailfish.Silica 1.0

MouseArea {

width: parent.width
height: Theme.paddingLarge

IconButton {
icon.source: "image://theme/icon-l-play"
}

Audio {
id: audio
onStatusChanged: {
console.log("Audio player status: " + status)
}
onError: {
console.log("Audio player error: " + error + ": " + errorString)
}
}

}
1 change: 1 addition & 0 deletions qml/components/ImageDisplay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MouseArea {
height: Math.max(imageBusy.height, pic.height)

function load(url) {
console.log(url)
imageBusy.running = true;
pic.source = url;
loaded = false;
Expand Down
17 changes: 11 additions & 6 deletions qml/pages/Browser.qml
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ Page {
Item {
width: 1;
height: Theme.paddingLarge
visible: !contentImage.loaded
visible: !contentMediaLoader.status === Loader.Ready
}

ImageDisplay {
id: contentImage
visible: false
Loader {
id: contentMediaLoader
width: parent.width
}

BusyIndicator {
Expand Down Expand Up @@ -287,8 +287,13 @@ Page {
if (content_type.substring(0, 6) == "image/") {
content.visible = false;
busyIndicator.visible = false;
contentImage.visible = true;
contentImage.load(url);
contentMediaLoader.source = "../components/ImageDisplay.qml"
contentMediaLoader.item.load(url);
} else if (content_type.substring(0, 6) == "audio/") {
content.visible = false;
busyIndicator.visible = false;
contentMediaLoader.source = "../components/AudioPlayer.qml"
requester.setMediaSource(contentMediaLoader.item.audio, url);
}
}

Expand Down
1 change: 1 addition & 0 deletions qml/pages/Details.qml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Page {
case 'T': return 'Telnet 3270';
case 'h': return _webURL ? 'URL' : 'HTML file';
case 's': return 'Sound file';
case 'gemini': return 'Gemini document';
default: return 'Unknown type: ' + type;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/customnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ QNetworkReply *CustomNetworkAccessManager::createRequest(QNetworkAccessManager::
return r;

} else if (request.url().scheme() == "geminicache") {
qInfo() << "Geminicache URL: " << request.url();
if (op != QNetworkAccessManager::Operation::GetOperation) return nullptr;
GeminiCachedRequestData *r = new GeminiCachedRequestData(request, this);
r->open(QIODevice::ReadOnly);
Expand Down
9 changes: 8 additions & 1 deletion src/requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QMetaEnum>
#include <QRegExp>
#include <QRegularExpression>
#include <QMediaPlayer>

Requester::Encoding encodingOf(const QByteArray& ba)
{
Expand Down Expand Up @@ -194,7 +195,7 @@ void Requester::metaDataChanged()
}
} else {
gemini_parse_level = GeminiNonText;
if (!gemini_content_type.startsWith("image/")) {
if (!gemini_content_type.startsWith("image/") && !gemini_content_type.startsWith("audio/")) {
r_error("Unsupported file-type: " + gemini_content_type);
r_text("This error message was generated on the client side.");
reply->abort();
Expand Down Expand Up @@ -439,6 +440,12 @@ void Requester::abort()
if (reply) reply->abort();
}

void Requester::setMediaSource(QObject *audio, QUrl url)
{
QMediaPlayer *player = qvariant_cast<QMediaPlayer*>(audio->property("mediaObject"));
player->setMedia({}, nam->get(QNetworkRequest(url)));
}

QString Requester::readLine() {
QString r;
QByteArray ba = reply->readLine();
Expand Down
3 changes: 3 additions & 0 deletions src/requester.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class Requester : public QObject
Q_INVOKABLE
void abort();

Q_INVOKABLE
void setMediaSource(QObject *audio, QUrl url);

signals:
void r_start(QString protocol);
void r_text(QString line);
Expand Down

0 comments on commit 890100a

Please sign in to comment.