How to keep audio active - now it works only during development phase

Hi,
I tried to develop an app for my personal use. My idea was to make a medicine reminder for me because I have the Parkinson decease and I have to take medicine every 3 hours. The app was meant to alarm 5 times every day: in the morning 9:00, 12:00, 15:00, 18:00 and 21:00. My app works now but it needs two features that I don’t know how to write: 2/2. how to make my app to output audio at the alarm time? Now it works like this: The audio is working only if I start the app with the USB-cable connected between my phone and my PC (Linux Mint & Qt Creator & Sony XPERIAX rooted to SailfishOS) After the app installation I can disconnect the USB cable and the app keeps on running. I can minimice the app worls and restore again and it still works. But if I close the app and disconnect the USB cable and run then animation etc. in App UI works but the audio does not work (The first question in another topic)

Below I have only the audio parts in the code not the alarm timings.
The UI is very simple: three words visible: “Tango” “Mute” “News”
It works like this:
Finger-click “Tango” and the app starts streaming audio from a net radio that plays Tango Agentino music.
Finger-click “News” and the app starts streaming audio from a net radio that plays news audio.

import QtQuick 2.0
import Sailfish.Silica 1.0
import QtMultimedia 5.6

Page {
id: page
allowedOrientations: Orientation.All
Item {
id: palikka
}
Text {
text: “tango”;
font.pointSize: 44;
width: 140; height: 1500; x:180; y:200; color:“white”
Audio {
id: playMusica
autoLoad: true
volume: 0.5
}
MouseArea {
id: playArea
anchors.fill: parent
onPressed: {
playMusica.stop(1,1)
playMusica.source= “https://ais-sa2.cdnstream1.com/2202_128.mp3
playMusica.play(1,1)
}
}
}
Text {
text: “Mute”;
font.pointSize: 44;
width: 140; height: 1500; x:359; y:200; color:“white”
Audio {
id: stopMusic
}
MouseArea {
id: stopArea
anchors.fill: parent
onPressed: {
playMusica.stop(1,1) }
}
}
Text {
text: “news”;
font.pointSize: 44;
width: 140; height: 1500; x:690; y:200; color:“white”
MouseArea {
id: clockArea2
anchors.fill: parent
onPressed: {
playMusica.stop(1,1)
playMusica.source = “https://edge8.audioxi.com/NT
playMusica.play(1,1)
}
}
}

Timer {
interval: 10000
running: true
repeat: true
}
}

Hi @Raimo57

A friend of mine has Parkinson’s, I wish I could do more to help him.

I thought I’d have a go with your code but ended up doing something a little different, in this case, only two titled buttons instead of three (they can be just headings instead if you prefer).

One button for Tango and the other for Radio. Either button requiring a simple tap to start or stop rather than muting/pausing.

I did not encounter any problems with audio with my code.

import QtQuick 2.0
import Sailfish.Silica 1.0
import QtMultimedia 5.6

Page {
    id: page

    allowedOrientations: Orientation.All

    Row {
        id: row
        spacing: 100
        anchors.centerIn: parent

        // TANGO
        Column {
            spacing: 40
            Label {
                font.capitalization: Font.AllUppercase
                anchors.horizontalCenter: parent.horizontalCenter
                text: playerMusica.playbackState === MediaPlayer.PlayingState ? "Playing" : "Stopped"
            }
            MediaPlayer { id: playerMusica; source: Qt.resolvedUrl("https://ais-sa2.cdnstream1.com/2202_128.mp3") }
            Button {
                width: Theme.itemSizeHuge
                onClicked: {
                    switch(playerMusica.playbackState) {
                        case MediaPlayer.PlayingState: playerMusica.pause(); break;
                        case MediaPlayer.PausedState: playerMusica.play(); break;
                        case MediaPlayer.StoppedState: playerMusica.play(); break;
                    }
                }
                Label { text: "TANGO"; anchors.centerIn: parent }
            }
            Component.onCompleted: playerMusica.pause()
        }
        // RADIO
        Column {
            spacing: 40
            Label {
                font.capitalization: Font.AllUppercase
                anchors.horizontalCenter: parent.horizontalCenter
                text: playerRadio.playbackState === MediaPlayer.PlayingState ? "Playing" : "Stopped"
            }
            MediaPlayer { id: playerRadio; source: Qt.resolvedUrl("https://edge8.audioxi.com/NT") }
            Button {
                width: Theme.itemSizeHuge
                Label { text: "RADIO"; anchors.centerIn: parent }
                onClicked: {
                    switch(playerRadio.playbackState) {
                        case MediaPlayer.PlayingState: playerRadio.pause(); break;
                        case MediaPlayer.PausedState: playerRadio.play(); break;
                        case MediaPlayer.StoppedState: playerRadio.play(); break;
                    }
                }
            }
            Component.onCompleted: playerRadio.pause()
        }
    }
}

Please use triple backtick ` to wrap your code

Test {
}
1 Like

Thank you! Nice code. However no change - it works similar as my code:

  1. like my code yourst plays the audio when the mobile device is connected (USB) to the development PC
  2. it keeps on working when the device is disconnected from the PC without closing the app
  3. but I can not hear the audio after closing the app in the phone and restarting in the phone also the texts above the buttos show only: “STOPPED”.

If yuo dont have that thirf issu then perhaps my complier/builder has something wrong?

When doing it via USB, how are you launching the app? How when disconnected?

Sounds like it could be related to sandboxing.

2 Likes

Apps launched by the SDK, whether over USB or WiFi, are not sandboxed.
Apps launched by pressing the icon gets sandboxed with the declared permissions in the .desktop file.
Indeed it sounds like you’ll have to declare some relevant permissions, or turn off sandboxing for the app.

1 Like

Thank You!
this was needed:

Permissions= Audio;Internet

2 Likes

My response is the same as @attah, sounds like a permissions problem…ah, you’ve solved while I was typing my response, I’m glad you got it working, it’s a nice feeling when your efforts pay off.

EDIT: Haha!, I’ve just encountered the same problem with my app, I forgot to add Audio to permissions, now my app works when disconnected from USB…I should have known this, doh!!, TAXI!!!

For the sake of detail and to help out others, GitHub - sailfishos/sailjail-permissions

1 Like