Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play feature is broken in Non Root access on termux in Android env. #124

Closed
sp33dsk8 opened this issue Feb 15, 2021 · 6 comments
Closed

Comments

@sp33dsk8
Copy link

I'm using a non-rooted android device with termux.
Surprisingly I was able to build PyRadio from source, however upon selecting a station I get roughly 5 seconds of audio and I receive a KeyError & Permission error on /proc directory.

PyRadio clearly is working however fundamentally does not work with my environment.

~/.local/bin $ ./pyradio --play
Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/psutil/_common.py", line 403, in wrapper
    return cache[key]
KeyError: (('/proc',), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/psutil/_pslinux.py", line 302, in <module>
    set_scputimes_ntuple("/proc")
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/psutil/_common.py", line 405, in wrapper
    ret = cache[key] = fun(*args, **kwargs)
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/psutil/_pslinux.py", line 269, in set_scputimes_ntuple
    with open_binary('%s/stat' % procfs_path) as f:
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/psutil/_common.py", line 711, in open_binary
    return open(fname, "rb", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/stat'

For me to make this change I would allow the user to decide if a stream is indeed playing and continue playing it versus what appears to be happening is pyradio checks with /proc to see if the stream is healthy in some way and KeyError on that check... Since I'm building from source this may be a easy adjustment.

@s-n-g
Copy link
Collaborator

s-n-g commented Feb 15, 2021

After looking at the error messges and a bit of googling, I can say that this is a psutil issue combined with the fact that your device is not rooted.

For example, have a look at this: aristocratos/bpytop#144

Since you do have playback (even for a few seconds) there may be a way to bypass this, if I can pin-point what triggers psutil.
So, just execute

pyradio -d

and post the file produced (~/pyradio.log)

Thisis a long shot, but, hey, might as well try before we give it up!

@sp33dsk8
Copy link
Author

I play a station that lasts about 4 seconds then fails and I exit
https://termbin.com/5ovy

I'm thinking the bypass is somewhere around this finally clause:

if sock:

@s-n-g
Copy link
Collaborator

s-n-g commented Feb 15, 2021

If anything inside

def updateMPVStatus(self, *args):
is causing psutil to break, there's nothing we can do... This function is executed in a different thread and it is responsible for the communication with mpv (communication through a socket). Changing anything in there, will probably render the player unusable.

BTW, can you try using mplayer (pyradio -u mplayer) or vlc (pyradio -u vlc)?
Both of them read stdout, so we may have more luck there...
Is it still breaking?

@sp33dsk8
Copy link
Author

sp33dsk8 commented Feb 15, 2021

Unfortunately vlc (installed from app store) is not accessible from command line ($ vlc) so pyradio wouldn't be able to call it.
I can't install mplayer either, using apt or pkg.

mpv works fine $ mpv http://somafm.com/secretagent.pls will directly play audio.

I know you're not targeting android with pyradio but the closest to getting something working officially would be using this Simple Protocol Player method.
https://android.stackexchange.com/a/205711

You've guarded user inputs in the config files well, I tried to break connection_timeout high and low but it constrains it back to default.

I've stripped out the lines for the timeout counter to activate in player.py ln1126-ln1137
Plays fine now :] Just a message about "Opening connection..." , I tried setting the connection_timeout_thread = True in hopes that that would short circuit it to think the job was done but to no avail.

@s-n-g
Copy link
Collaborator

s-n-g commented Feb 15, 2021

Wow!
That was amazing!
Kudos to you!

@s-n-g
Copy link
Collaborator

s-n-g commented Feb 15, 2021

BTW, If you do post a tutorial or guide or something about how you did this, please do send us a link.

It would be really interesting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants