Download video in Background Android

122 views
Skip to first unread message

Degenerate Tech

unread,
Nov 4, 2020, 11:07:58 PM11/4/20
to Kivy users support
I want to make an app which will download some video ...in background in Android OS
...I have no idea how to use ..I have read python for Android documentation to start a service ....but it is not so clear..for me ...can any one please give me a simple example ?

Anoop Rana

unread,
Nov 4, 2020, 11:15:08 PM11/4/20
to kivy-...@googlegroups.com
One way is to use multiprocessing.Process.That way it will not block the program as it will go on in the background.When it is finished downloading the file ,you can just check if that process is alive or not.

On Thu, 5 Nov 2020, 09:38 Degenerate Tech, <sksah...@gmail.com> wrote:
I want to make an app which will download some video ...in background in Android OS
...I have no idea how to use ..I have read python for Android documentation to start a service ....but it is not so clear..for me ...can any one please give me a simple example ?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/dac97d83-e89d-4787-97b0-7c983893b739o%40googlegroups.com.

Degenerate Tech

unread,
Nov 4, 2020, 11:19:11 PM11/4/20
to Kivy users support
what will be happen .?. when my app be in pause mode...or i will use another app ?

Anoop Rana

unread,
Nov 4, 2020, 11:23:33 PM11/4/20
to kivy-...@googlegroups.com
1)You can navigate through different sections of your (same) app when the file will be downloading.
2) But When your same app will be on pause i suppose the downloading process should go on.You have to test out this last statement as i am not 100% sure what will happen if  your app is on pause.

Degenerate Tech

unread,
Nov 4, 2020, 11:31:11 PM11/4/20
to Kivy users support
see this ..I have to use service in android

https://python-for-
android.readthedocs.io/en/latest/services/

Degenerate Tech

unread,
Nov 4, 2020, 11:31:45 PM11/4/20
to Kivy users support
I want a practical example ..

Degenerate Tech

unread,
Nov 4, 2020, 11:33:19 PM11/4/20
to Kivy users support

Robert Flatt

unread,
Nov 5, 2020, 12:17:48 AM11/5/20
to Kivy users support
2) But When your same app will be on pause i suppose the downloading process should go on.You have to test out this last statement as i am not 100% sure what will happen if  your app is on pause.

On app pause the download will pause.
For implementation consider a thread rather than a new process - which may not work.

As for a service, I don't know of any examples - time to figure it out from the docs ;)

On Wednesday, November 4, 2020 at 6:33:19 PM UTC-10, Degenerate Tech wrote:
https://python-for-android.readthedocs.io/en/latest/services/

planckp...@gmail.com

unread,
Nov 5, 2020, 9:59:48 PM11/5/20
to Kivy users support
It mostly works :(
Service stop fails on the desktop and on Android for different reasons.
If you figure out stop please post.
Message has been deleted

Robert Flatt

unread,
Nov 5, 2020, 11:32:43 PM11/5/20
to Kivy users support
I played with this a little, could not see how to get service stop to work. So modified to implement mute instead
See also notes at the top of main.py
Should be enough for you to play with.

See attached
service.py
buildozer.spec
main.py

Robert Flatt

unread,
Nov 6, 2020, 4:56:41 PM11/6/20
to Kivy users support
Got it, services start, stop, and restart.
See notes at the top of main.py
Tested on Windows and Android


service.py
buildozer.spec
main.py

Degenerate Tech

unread,
Nov 6, 2020, 5:01:50 PM11/6/20
to Kivy users support
thank you sir..i will test it.

Robert Flatt

unread,
Nov 6, 2020, 9:03:49 PM11/6/20
to Kivy users support
Thanks, there is not enough testing around here :(

The case I'm not certain about is if the service 'dies' or 'is killed'; then the app won't know.
I don't think 'dies' is a real case except in the case of a clueless programmer
But Android has a mind of its own ;) so my assumptions may be incorrect.

Do you know?

Degenerate Tech

unread,
Jan 4, 2021, 9:04:16 AM1/4/21
to Kivy users support
i want to pass python object from main.py to service.py  here args is my python object 

in main.py 
def send(self, args):
print('@@@@@@@',args)
if self.service:
self.client.send_message(b'/sping', [args,])
print('sending')

###in service,py 
def ping(*_):
    'answer to ping messages'
    print(_)


but it is showing error

[INFO   ] [Base        ] Leaving application in progress...
Traceback (most recent call last):
  File "main.py", line 209, in <module>
    MyApp().run()
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/app.py", line 950, in run
    runTouchApp()
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/base.py", line 582, in runTouchApp
    EventLoop.mainloop()
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/base.py", line 347, in mainloop
    self.idle()
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/base.py", line 391, in idle
    self.dispatch_input()
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/base.py", line 342, in dispatch_input
    post_dispatch_input(*pop(0))
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/base.py", line 308, in post_dispatch_input
    wid.dispatch('on_touch_up', me)
  File "kivy/_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
  File "/home/sahil/app_tube/kivymd/uix/behaviors/ripple_behavior.py", line 295, in on_touch_up
    return super().on_touch_up(touch)
  File "/home/sahil/app_tube/kivymd/uix/button.py", line 1014, in on_touch_up
    return super().on_touch_up(touch)
  File "/home/sahil/app_tube/kivymd/uix/button.py", line 947, in on_touch_up
    return super().on_touch_up(touch)
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/uix/behaviors/button.py", line 179, in on_touch_up
    self.dispatch('on_release')
  File "kivy/_event.pyx", line 705, in kivy._event.EventDispatcher.dispatch
  File "kivy/_event.pyx", line 1248, in kivy._event.EventObservers.dispatch
  File "kivy/_event.pyx", line 1132, in kivy._event.EventObservers._dispatch
  File "/home/sahil/.local/lib/python3.6/site-packages/kivy/lang/builder.py", line 57, in custom_callback
    exec(__kvlang__.co_value, idmap)
  File "/home/sahil/app_tube/myapp.kv", line 138, in <module>
    on_release:root._play()
  File "main.py", line 82, in _play
    self.mainobj.send(self.pfyobj.allstreams)
  File "main.py", line 179, in send
    self.client.send_message(b'/sping', [args,])
  File "/home/sahil/app_tube/oscpy/client.py", line 139, in send_message
    encoding_errors=self.encoding_errors
  File "/home/sahil/app_tube/oscpy/client.py", line 65, in send_message
    encoding_errors=encoding_errors
  File "/home/sahil/app_tube/oscpy/parser.py", line 235, in format_message
    .format(value, [x[0] for x in WRITERS])
TypeError: unable to find a writer for value [audio:webm@50k, audio:webm@70k, audio:m4a@128k, audio:webm@160k, video:mp4@256x144, video:webm@256x144, video:mp4@256x144
, video:mp4@426x240, video:webm@426x240, video:mp4@426x240, video:mp4@640x360, video:webm@640x360, video:mp4@640x360, video:webm@854x480, video:mp4@854x480, video:mp4@8
54x480, video:mp4@1280x720, video:webm@1280x720, video:mp4@1280x720, video:mp4@1920x1080, video:webm@1920x1080, video:mp4@1920x1080, normal:mp4@640x360, normal:mp4@1280
x720], type not in: [<class 'float'>, <class 'int'>, <class 'bytes'>, <class 'str'>, <class 'bytearray'>, True, False, None, <class 'oscpy.parser.MidiTuple'>].

planckp...@gmail.com

unread,
Jan 4, 2021, 12:43:52 PM1/4/21
to Kivy users support
The protocol is simple to use, OSC addresses look like http URLs, and accept various basic types, such as string, float, int, etc. You can think of it basically as an http POST, with less overhead.

I read that as, one can't send an arbitrary object.
Clearly oscpy could not pass a memory reference between processes.
And to me it looks like the message says oscpy can't encode this memory reference.

Perhaps a solution would be save the object as a file, and pass the file path in the message?

Degenerate Tech

unread,
Jan 4, 2021, 12:46:53 PM1/4/21
to Kivy users support
and one problem is here background service not staying when i am opening other apps in android .

Degenerate Tech

unread,
Jan 4, 2021, 2:04:21 PM1/4/21
to Kivy users support
def send(self, args):
print('2@@@@@@@',args)
if self.service:
self.client.send_message(b'/ping', [args[0].encode('utf8'),str(args[1]).encode('utf8')])
print('sending')


above code used to start download..file is not downloading in android 


class Plate(BoxLayout):
lbl=StringProperty('')
pfyobj=ObjectProperty(None)
mainobj=ObjectProperty(None)
csi=NumericProperty(0)
def __init__(self,**k):
super().__init__(**k)


def on_kv_post(self,obj):
self.ids.id_fsize.text=f'Size: {hurry.filesize.size(self.pfyobj.allstreams[self.csi].get_filesize())}'

def _play(self):
#self.mainobj._source= self.pfyobj.allstreams[self.csi].url_https
#self.mainobj.ids.id_sview.scroll_to(self.mainobj.ids.id_vplate, padding=10, animate=True)
#self.mainobj.stop_service()
self.mainobj.send((self.mainobj.ids.id_vlink.text,self.csi))

def _download(self):
self.mainobj.start_service()


_download () stating service 
and _play method used to call send() method 


Problem is service is starting but file not downloading in android .but in ubuntu everything working fine .
 
On Monday, January 4, 2021 at 11:13:52 PM UTC+5:30 planckp...@gmail.com wrote:
main.py
buildozer.spec
service.py

planckp...@gmail.com

unread,
Jan 4, 2021, 4:44:16 PM1/4/21
to Kivy users support
Run the debugger, why is the service stopping?

It is possible, but not definitely the case, that Android is killing the service

Degenerate Tech

unread,
Jan 5, 2021, 2:47:38 AM1/5/21
to Kivy users support
please see my code. why  download not starting

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/7WKYPLMoZac/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fdcc2e20-08b4-4065-8468-b7bacd0c5eafn%40googlegroups.com.

Degenerate Tech

unread,
Jan 5, 2021, 12:29:22 PM1/5/21
to Kivy users support
please help

planckp...@gmail.com

unread,
Jan 5, 2021, 8:16:07 PM1/5/21
to Kivy users support
The assumption that I can magically determine the issue without doing the work is misplaced.

If you are asking me to do the work for you by running the debugger, my answer is a very clear no.
My life is too important to me to spend my time doing your work for you.

Degenerate Tech

unread,
Jan 6, 2021, 12:12:10 AM1/6/21
to Kivy users support
Reply all
Reply to author
Forward
0 new messages