Page 2 of 3
Re: How to play music from a URL on Android?
Posted: Wed Apr 06, 2022 1:37 pm
by liveCode
This is my code:
Code: Select all
if the environment = "mobile" then
## Create a native player:
mobilecontrolcreate "player", "playSing"
## set more properies here...
## Set filename or URL for this player:
mobilecontrolset "playSing","filename",_playMusic
## Finally start that thing:
mobileControlDo "playSing", "play"
else
set the filename of player "sing" of cd "setting"to _playMusic
start player "sing" of cd "setting"
end if
Re: How to play music from a URL on Android?
Posted: Wed Apr 06, 2022 1:52 pm
by Klaus
OK, looks correct now.
Is _playMusis a httpS url?
Maybe you can check the result?
Code: Select all
...
mobilecontrolset "playSing","filename",_playMusic
if the result <> EMPTY then
answer "Filename:" && the result
end if
## Finally start that thing:
mobileControlDo "playSing", "play"
if the result <> EMPTY then
answer "Play:" && the result
end if
...
Not sure if that works on mobile.
Re: How to play music from a URL on Android?
Posted: Wed Apr 06, 2022 5:29 pm
by liveCode
That's what he gave me
Filename:1
Play:13
what am I doing now?
This is my full code:
In this button the code:
Code: Select all
PlayMusic "https://tcrvo.ml/12.mp3"
And stack:
Code: Select all
on PlayMusic _playMusic
show widget "waitSing"
show field "waitSing"
if the environment = "mobile" then
## Create a native player:
mobilecontrolcreate "player", "playSing"
## set more properies here...
## Set filename or URL for this player:
mobilecontrolset "playSing","filename",_playMusic
if the result <> EMPTY then
answer "Filename:" && the result
end if
## Finally start that thing:
mobileControlDo "playSing", "play"
if the result <> EMPTY then
answer "Play:" && the result
end if
else
set the filename of player "sing" of cd "setting"to _playMusic
start player "sing" of cd "setting"
end if
put url(_playMusic) into tVar
if the result <> EMPTY then
then
answer "We're unable to play the song"
end if
hide widget "waitSing"
hide field "waitSing"
end PlayMusic
Re: How to play music from a URL on Android?
Posted: Wed Apr 06, 2022 5:35 pm
by Klaus
Sorry, no idea, I was expecting something like "can't set filename" as the result or something more meaningful.
And no mention of this in the dcitionary.

Re: How to play music from a URL on Android?
Posted: Wed Apr 06, 2022 5:40 pm
by liveCode
Maybe there are more ways?
Re: How to play music from a URL on Android?
Posted: Wed Apr 06, 2022 9:24 pm
by jacque
Looks like you need to add a few more properties. This works for me on Android:
Code: Select all
if the environment = "mobile" then
## Create a native player:
mobilecontrolcreate "player", "playSing"
## set more properies here...
mobilecontrolset "playSing","rect","10,10,200,50" -- adjust this to fit your app layout
mobilecontrolset "playSing","visible",true
mobilecontrolset "playSing","showController",true
## Set filename or URL for this player:
mobilecontrolset "playSing","filename",_playMusic
## Finally start that thing:
mobileControlDo "playSing", "play"
else
set the filename of player "sing" of cd "setting"to _playMusic
start player "sing" of cd "setting"
end if
You can set the visible and showController to false if you don't want to see it. It appears that at least a rect is required. The default is to show the controller and the player. If you don't want the player to show, the actual rect isn't very important.
Also, make sure you have ticked the Internet checkbox in Android standalone settings. Also be sure you have Internet and (if available) TSNet selected in standalone inclusions.
When you're done with it, use mobileControlDelete to remove it from memory. That's required, since scripted mobile controls never go away until you quit the app or specifically remove them, and can interfere with other cards or controls.
I like the music.
Edit: You can delete the widget since you aren't using it. Also, the final "if" clause at the end of your handler is missing an "end if" and it has two "then"s. And typically there's a space between "url" and the url itself, though apparently the way you have it doesn't error. I do this:
Re: How to play music from a URL on Android?
Posted: Thu Apr 07, 2022 7:59 pm
by liveCode
This works the problem is that you have to wait 5 seconds for it to work
Re: How to play music from a URL on Android?
Posted: Fri Apr 08, 2022 9:34 am
by Klaus
You could download the file when the app starts and then play it via "play file...".
Code: Select all
...
put "https://tcrvo.ml/12.mp3" into tURL
put specialfolderpath("documents") & "/12.mp3" into tFile
libURLDownloadToFile tURL,tFile
...
Check the dictionary for more options of that command.
Re: How to play music from a URL on Android?
Posted: Fri Apr 08, 2022 9:56 am
by liveCode
Thank you.
Re: How to play music from a URL on Android?
Posted: Fri Apr 08, 2022 10:56 am
by liveCode
Does it work on Android?
Re: How to play music from a URL on Android?
Posted: Fri Apr 08, 2022 1:33 pm
by Klaus
Why don't you just try?
You cell-phone will not explode, promised!

Re: How to play music from a URL on Android?
Posted: Fri Apr 08, 2022 5:59 pm
by jacque
liveCode wrote: Fri Apr 08, 2022 10:56 am
Does it work on Android?
It's supposed to, I've never used it. You could also set the URL of the native player when your app launches, and then only issue the play command when it's time to hear the music.
Re: How to play music from a URL on Android?
Posted: Sat Apr 09, 2022 6:47 pm
by liveCode
It works but there is a problem ...
I want this command to run the first time the user launches the app
The problem is that it takes a long time because I am loading 18 files
Then the user has to wait a long time
How can I make it happen in the background?
Re: How to play music from a URL on Android?
Posted: Sat Apr 09, 2022 7:02 pm
by Klaus
A possible solution:
1. when the app start check if (one of) the files are already in the user documents folder
2. If not start to download all files in a repeat loop, except one, that you
3. added to your standalone (Add files), so the first song can be played immediately when the app start, if that is neccessary.
libURLDownloadToFile tURL,tFile is asynchronous, means it will work in the background.
Re: How to play music from a URL on Android?
Posted: Sat Apr 09, 2022 7:05 pm
by liveCode
How do I check if one of the files is already found?