How to play music from a URL on Android?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

How to play music from a URL on Android?

Post by liveCode » Fri Apr 01, 2022 11:22 am

How to play music from a URL on Android?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

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

Post by jacque » Fri Apr 01, 2022 5:39 pm

Use a player control and set its URL property. The music must be in a format that Android supports, mp3 is common.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Fri Apr 01, 2022 5:53 pm

Isn't the "player object" desktop only?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

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

Post by jacque » Fri Apr 01, 2022 6:04 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Fri Apr 01, 2022 6:28 pm

Ah, yes, true, there you can also set the URL for the created player.

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Sun Apr 03, 2022 5:18 pm

So how do I do that?

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Sun Apr 03, 2022 6:42 pm

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
...

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Mon Apr 04, 2022 7:46 pm

What do I put in "filename"?

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

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

Post by stam » Mon Apr 04, 2022 8:05 pm

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

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Mon Apr 04, 2022 8:57 pm

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!

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Wed Apr 06, 2022 12:46 pm

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
Last edited by liveCode on Wed Apr 06, 2022 1:31 pm, edited 2 times in total.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Wed Apr 06, 2022 12:59 pm

There is a SPACE between _ and play in the script:
_ playMusic

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Wed Apr 06, 2022 1:21 pm

There is no space in my code
I accidentally added it when I posted

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » 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

And change this:

Code: Select all

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

liveCode
Posts: 119
Joined: Sun Oct 17, 2021 5:53 pm

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

Post by liveCode » Wed Apr 06, 2022 1:31 pm

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”