UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Python should reset PulseAudio

    Scheduled Pinned Locked Moved App Development
    25 Posts 4 Posters 3.7k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • D Offline
        digi6622
        last edited by

        Hi there,
        in the UT terminal the following command is executed flawlessly:

        pulseaudio -k
        

        Pulseaudio stops and a few seconds later it starts again.

        If I try a clickable script with python section:

        import os
        import signal
        import subprocess
        
        pulseStop = 'pulseaudio -k'
        
        def procPulseReset(name):
          os.system(pulseStop)
        

        I get following message:

        E: [pulseaudio] main.c: Konnte Prozess nicht abbrechen: No such process
        

        I've set AppArmor policy "audio".
        Have someone an idea where is the problem ?

        arubislanderA 1 Reply Last reply Reply Quote 0
        • arubislanderA Online
          arubislander @digi6622
          last edited by

          @digi6622 Is this you trying to stop playback by stopping the pulseaudio service?

          That command works in the Terminal app because it is an unconfined system app. Confined apps are not allowed to go about randomly controlling other processes.

          πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
          Happily running Ubuntu Touch
          Google Pixel 3a (20.04 DEV)
          JingPad (24.04 preview)
          Meizu Pro 5 (16.04 DEV)

          D 1 Reply Last reply Reply Quote 0
          • D Offline
            digi6622 @arubislander
            last edited by

            @arubislander
            Thanks, Arubislander.
            It's a little bit frustrating but I will continue to search for the right solution.

            arubislanderA 2 Replies Last reply Reply Quote 0
            • arubislanderA Online
              arubislander @digi6622
              last edited by

              @digi6622 Did you try maybe playing a short audio file in your app? Does it then stop the music app playback? If so, then refine that process: provide an empty source, or maybe just invoke stop() on the media player without playing anything at all?
              I suspect what you are trying to achieve might even be possible without using Python at all.

              If of course your aim is to experiment with Python on Ubuntu Touch, then maybe try something that doesn't involve manipulating system processes from the command line πŸ™‚

              πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
              Happily running Ubuntu Touch
              Google Pixel 3a (20.04 DEV)
              JingPad (24.04 preview)
              Meizu Pro 5 (16.04 DEV)

              1 Reply Last reply Reply Quote 0
              • arubislanderA Online
                arubislander @digi6622
                last edited by

                @digi6622 You might want to take a look at this Intro to Development on UTouch. There is also an email address, training-support(at)ubports(dot)com, where you can request assistance if there is anything you don't understand.

                Of course there is also the App Dev Telegram channel for more unstructured questions and maybe more immediate assistance.

                πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                Happily running Ubuntu Touch
                Google Pixel 3a (20.04 DEV)
                JingPad (24.04 preview)
                Meizu Pro 5 (16.04 DEV)

                D 1 Reply Last reply Reply Quote 0
                • D Offline
                  digi6622 @arubislander
                  last edited by

                  @arubislander
                  Thanks for your kind support and the encouraging words.

                  I think I found a solution in

                  https://forums.ubports.com/topic/7981/change-volume-from-command-line/10?lang=de

                  At least it sounds like a possible solution if UT plays along.:face_with_raised_eyebrow: :grinning_face_with_smiling_eyes:

                  The command "pactl" should do the trick.

                  arubislanderA 1 Reply Last reply Reply Quote 0
                  • arubislanderA Online
                    arubislander @digi6622
                    last edited by arubislander

                    @digi6622 said in Python should reset PulseAudio:

                    The command "pactl" should do the trick.

                    I hate to rain on your parade, but executing an external command from a confined app is simply not supported.

                    But, why would you want to 'stop' playback by changing the volume of the speakers? Maybe take a look here for doing what you might want.

                    In short, your app will not be able to execute any command line tools unless you bundle those tools in the click with your app.

                    πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                    Happily running Ubuntu Touch
                    Google Pixel 3a (20.04 DEV)
                    JingPad (24.04 preview)
                    Meizu Pro 5 (16.04 DEV)

                    D 1 Reply Last reply Reply Quote 0
                    • D Offline
                      digi6622 @arubislander
                      last edited by

                      @arubislander
                      Thanks again.
                      Now, I give up the project. Maybe someday I will start a new and completly different.

                      arubislanderA 1 Reply Last reply Reply Quote 0
                      • arubislanderA Online
                        arubislander @digi6622
                        last edited by

                        @digi6622 I can only encourage you not to give up if the project is important to you. Maybe slide I to my DM's to talk it through? I am sure it is possible to achieve your goal in a way that does not fight the system.

                        πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                        Happily running Ubuntu Touch
                        Google Pixel 3a (20.04 DEV)
                        JingPad (24.04 preview)
                        Meizu Pro 5 (16.04 DEV)

                        D 1 Reply Last reply Reply Quote 0
                        • D Offline
                          digi6622 @arubislander
                          last edited by

                          @arubislander

                          Maybe slide I to my DM's to talk it through?

                          That would be really nice !
                          In short words what my app should do:

                          • Select a certain number of minutes (it already works)

                          • Go to sleep for the number of minutes (works too)

                          • After this time the app close media-hub or decrease volume of this soundchannel or mute pulseaudio (= my problem)

                          arubislanderA 1 Reply Last reply Reply Quote 0
                          • arubislanderA Online
                            arubislander @digi6622
                            last edited by

                            @digi6622 and is using Python a hard requirement?

                            πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                            Happily running Ubuntu Touch
                            Google Pixel 3a (20.04 DEV)
                            JingPad (24.04 preview)
                            Meizu Pro 5 (16.04 DEV)

                            D 1 Reply Last reply Reply Quote 0
                            • D Offline
                              digi6622 @arubislander
                              last edited by

                              @arubislander said in Python should reset PulseAudio:

                              @digi6622 and is using Python a hard requirement?

                              It would be nice if possible. I'm not fit in C++ or other codings.

                              arubislanderA 1 Reply Last reply Reply Quote 0
                              • arubislanderA Online
                                arubislander @digi6622
                                last edited by

                                @digi6622 I ask because for what you want to do, you probably o ly need QML and some Javascript.

                                πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                                Happily running Ubuntu Touch
                                Google Pixel 3a (20.04 DEV)
                                JingPad (24.04 preview)
                                Meizu Pro 5 (16.04 DEV)

                                D 1 Reply Last reply Reply Quote 0
                                • D Offline
                                  digi6622 @arubislander
                                  last edited by

                                  @arubislander
                                  QML and Javascript are okay.

                                  arubislanderA 1 Reply Last reply Reply Quote 0
                                  • arubislanderA Online
                                    arubislander @digi6622
                                    last edited by arubislander

                                    @digi6622 I have prepared a code snippet that does what you want. The Main.qml references silence.wav, which is a one second of silence wav file in the assets folder, created with Audacity. When the button is clicked the wav file is played, interrupting and superceding anything else that might have been playing.

                                    Don't forget to add the "multimedia" profile to your apparmor file (appname.apparmor).

                                    This can be run in a confined app, and does not require trying to manipulate commands and services external to the application.

                                    I would like to reiterate that, as a proof of concept and by way of exercise, this is all very well. But a proper sleep functionality should be either implemented in the OS somewhere, as a global feature (maybe in settings?), or in the Music app itself as a local feature.

                                    πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                                    Happily running Ubuntu Touch
                                    Google Pixel 3a (20.04 DEV)
                                    JingPad (24.04 preview)
                                    Meizu Pro 5 (16.04 DEV)

                                    D 1 Reply Last reply Reply Quote 1
                                    • D Offline
                                      digi6622 @arubislander
                                      last edited by

                                      @arubislander
                                      Thanks again !!!
                                      It sounds very simple. Actually, I had assumed that the sound outputs (media-hub and playing a wav-file) were on different sound slots and thus did not affect each other. Therefore I did not think in this direction at all. But I give it a try. Thanks a lot.

                                      I would like to reiterate that, as a proof of concept and by way of exercise, this is all very well. But a proper sleep functionality should be either implemented in the OS somewhere, as a global feature (maybe in settings?), or in the Music app itself as a local feature.

                                      I understand your concerns. Neverteheless I would like to offer my app in the OpenStore, because some members here in the forum (including me) wish this app. The maintainers of UT and MediaPlayer did not respond to this request.

                                      klhK 1 Reply Last reply Reply Quote 0
                                      • klhK Offline
                                        klh @digi6622
                                        last edited by

                                        @digi6622 I don't see any feature requests about what you describe here: https://gitlab.com/ubports/development/core/mediaplayer-app/-/issues
                                        Where was the request made if nobody responded to it?

                                        D 1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          digi6622 @klh
                                          last edited by

                                          @klh said in Python should reset PulseAudio:

                                          @digi6622 I don't see any feature requests about what you describe here: https://gitlab.com/ubports/development/core/mediaplayer-app/-/issues
                                          Where was the request made if nobody responded to it?

                                          You can find requests here:

                                          https://open-store.io/app/com.ubuntu.music
                                          https://forums.ubports.com/topic/4879/flas-sleep-timer

                                          arubislanderA 1 Reply Last reply Reply Quote 0
                                          • D Offline
                                            digi6622
                                            last edited by

                                            Just a few basic thoughts from me:
                                            Many mobile OS have disappeared because there simply wasn't much choice in apps. UT also doesn't have a wide distribution because there aren't many apps available. My wife would never switch from Android to UT for this reason. She simply lacks the little "helpers".
                                            Therefore, it is important that every app, no matter how small, should be gratefully accepted. Every developer should be encouraged to continue to work for the community in his spare time (thanks to arubislander). His intentions should not be questioned. It doesn't have to be the huge "you-can-do-anything" app. Even the smallest app strengthens the OS. That's the only way UT can become something big.

                                            AppLeeA 1 Reply Last reply Reply Quote 1
                                            • arubislanderA Online
                                              arubislander @digi6622
                                              last edited by

                                              @digi6622 said in Python should reset PulseAudio:

                                              You can find requests here:
                                              https://open-store.io/app/com.ubuntu.music

                                              The app ratings section is not the best place to make requests.

                                              There is already a feature request here, and a merge request here. Please upvote the issue to signal interest. The MR is still a WIP by the way, maybe offer to help bring it to a state where it could be merged into the app?

                                              πŸ‡¦πŸ‡Ό πŸ‡³πŸ‡± πŸ‡ΊπŸ‡Έ πŸ‡ͺπŸ‡Έ
                                              Happily running Ubuntu Touch
                                              Google Pixel 3a (20.04 DEV)
                                              JingPad (24.04 preview)
                                              Meizu Pro 5 (16.04 DEV)

                                              klhK 1 Reply Last reply Reply Quote 0
                                              • First post
                                                Last post