Page 1 of 3

How to play music from a URL on Android?

Posted: Fri Apr 01, 2022 11:22 am
by liveCode
How to play music from a URL on Android?

Re: How to play music from a URL on Android?

Posted: Fri Apr 01, 2022 5:39 pm
by jacque
Use a player control and set its URL property. The music must be in a format that Android supports, mp3 is common.

Re: How to play music from a URL on Android?

Posted: Fri Apr 01, 2022 5:53 pm
by Klaus
Isn't the "player object" desktop only?

Re: How to play music from a URL on Android?

Posted: Fri Apr 01, 2022 6:04 pm
by jacque
Klaus wrote:
Fri Apr 01, 2022 5:53 pm
Isn't the "player object" desktop only?
Oh, right. Sorry. Android needs the scripted player using mobileControlCreate.

Re: How to play music from a URL on Android?

Posted: Fri Apr 01, 2022 6:28 pm
by Klaus
Ah, yes, true, there you can also set the URL for the created player.

Re: How to play music from a URL on Android?

Posted: Sun Apr 03, 2022 5:18 pm
by liveCode
So how do I do that?

Re: How to play music from a URL on Android?

Posted: Sun Apr 03, 2022 6:42 pm
by Klaus
Check "mobilecontrolcreate", "mobilecontroldo" and "mobilecontrolset" in the dictionary.
There are some example on how to use these commands.

And don't forget, they will only work on MOBILE and throw an error on desktop, so use:

Code: Select all

...
if the environment = "mobile" then
   ## Create a native player:
   mobilecontrolcreate "player", "name for your player"
   ## set more properies here...

   ## Set filename or URL for this player:
   mobilecontrolset "name for your player","filename","https://complete URL here..."

   ## Finally start that thing:
   mobileControlDo "name for your player", "play"
end if
...

Re: How to play music from a URL on Android?

Posted: Mon Apr 04, 2022 7:46 pm
by liveCode
What do I put in "filename"?

Re: How to play music from a URL on Android?

Posted: Mon Apr 04, 2022 8:05 pm
by stam
liveCode wrote:
Mon Apr 04, 2022 7:46 pm
What do I put in "filename"?
search the dictionary for mobileControlSet, scroll down to 'player' section and it will tell you

Re: How to play music from a URL on Android?

Posted: Mon Apr 04, 2022 8:57 pm
by Klaus
liveCode wrote:
Mon Apr 04, 2022 7:46 pm
What do I put in "filename"?
Nothing!
This is the name of the property which has to be put in QUOTES with "mobilecontrolset".

I may repeat myself:
Check "mobilecontrolcreate", "mobilecontroldo" and "mobilecontrolset" in the dictionary.
There are some example on how to use these commands.
So please DO!

Re: How to play music from a URL on Android?

Posted: Wed Apr 06, 2022 12:46 pm
by liveCode
This is the code I put:

Code: Select all

  if the environment = "mobile" then
       ## Create a native player:
       mobilecontrolcreate "player", "playSing"
      
       ## set more properties here ...
      
       ## Set filename or URL for this player:
       mobilecontrolset "playSing", "playSing", _playMusic
      
       ## Finally start that thing:
       mobileControlDo "playSing", "play"
    else
       set the filename of player "sing" or cd "setting" to _playMusic
       start player "sing" of cd "setting"
    end if
But it still does not work
Of course in the variable _playMusic I put the URL

Re: How to play music from a URL on Android?

Posted: Wed Apr 06, 2022 12:59 pm
by Klaus
There is a SPACE between _ and play in the script:
_ playMusic

Re: How to play music from a URL on Android?

Posted: Wed Apr 06, 2022 1:21 pm
by liveCode
There is no space in my code
I accidentally added it when I posted

Re: How to play music from a URL on Android?

Posted: Wed Apr 06, 2022 1:25 pm
by Klaus
OK, but this cannot work:

Code: Select all

...
## Set filename or URL for this player:
mobilecontrolset "playSing", "playSing", _playMusic
...
Guess why!
Hint: FILENAME

And change this:

Code: Select all

...
## start player "sing" or cd "setting"
## to
start player "sing" OF cd "setting"
...

Re: How to play music from a URL on Android?

Posted: Wed Apr 06, 2022 1:31 pm
by liveCode
Klaus wrote:
Wed Apr 06, 2022 1:25 pm
OK, but this cannot work:

Code: Select all

...
## Set filename or URL for this player:
mobilecontrolset "playSing", "playSing", _playMusic
...
Guess why!
Hint: FILENAME
I changed back to filename and it still did not work