Nativescript: Audio Streaming

Created on 3 Oct 2016  路  10Comments  路  Source: NativeScript/NativeScript

I'm kinda stuck right now. I'm building an app that streams audio live. On getting to the implementation part, I found out its almost impossible to achieve this. NativeScript uses HTTP requests that waits for a response before doing anything.

I need help please. How do you implement ONE-WAY live streaming (audio) i.e The app only streams from one location, doesn't need the users to respond. More like how radio works / spotify. Please help.

question

Most helpful comment

@paschaldev Hi, I need to archive the same now. Did you come up with a solution and would you like to share pls?

All 10 comments

Hello @paschaldev

There are several possibilities for implementing audio-stream in your application.

The first one is nativescript-spotify - a plugin that uses Spotify API which on the other hand supports audio stream (you should have Premium developer account in order to use this feature).

Another applicable option is to create your own plugin
with an API that suits your needs.
Here are some possible native APIs that are good for streaming audio and can be implemented as NativeScript plugin.

Audiostream (for Android0

Streaming Kit (for iOS)

If you need more information on how to create plugin in NativeScript i can recommend both the documentation articles and this blog thread

@NickIliev

The spotify API requires a premium account which is kinda expensive for my budget. I'll prefer to write my own plugin.

I just need to be sure its possible to do this with the native API you recommended. Remember I'm not streaming an audio file but rather from a URL that might not really have a .mp3 extension or something like that. Please I need answers

Hey @paschaldev

I am not familiar with the streaming APIs - I have just make a quick research for two possible solutions. Basically, almost all native APIs can be implemented with marshalling into a NativeScritp plugin.
So it is really a matter if the API you are converting to a plugin support your needs.
For example, after a short research, I noticed that AudioStream API comes with a public constructor that expect an InetAddress as a param.

AudioStream (InetAddress address)

with data conversion to NativeScript, it should look something like this

var audioStream = android.net.rtp.AudioStream(java.net.InetAddress.getByAddress(host, bytes))

https://developer.android.com/reference/java/net/InetAddress.html#getByAddress(java.lang.String, byte[])

You should do some research on whether the stream you provide is needing some special codec or technology and see if the API you ar using is supporting it.

Thank you very much. For example, checkout this url that streams live audio.

http://icy2.abacast.com/megalectrics-thebeatmp3-32

Something like this URL is what I'll be using, a non-ending streaming like that. I'll make my own research too tho. Thank you very much. Please do check the url.

@paschaldev

As far as I understood the link you send mme is a part of this system : http://www.wostreaming.com/products/audio-stream-management/

And in the description of the services they provide I saw the following lines:

Choose from traditional audio streaming protocols or our HTTP Live Streaming (HLS) network to reach smartphone and connected-device users.
Supports all popular file formats, including MP3 andAAC and operating systems devices including Windows, OSX,iOS and Android.

So the service they provide do have multiple options to send the content including HTTP live streaming formats and different file formats and also iOS and Android APIs

@NickIliev

Thank you. I just need to know, is it possible to plugin that URL directly in the Android & iOs API so I can start work on making a plugin.

What I'm mostly concerned about is the way data will flow, the possibility. Will there be a kind of an open connection to the URL that never ends and stuffs like that. I don't know if you understand me, but I'll look up those APIs anyway and see how far I can go.

I'm hoping i'll be able to do something like this according to your example.

var audioStream = android.net.rtp.AudioStream(java.net.InetAddress.getByAddress(url-of-the-audio-stream-like-the-one-i-posted-earlier, bytes))

I don't know what the use of the bytes argument will be but anyways, I'll start work and see how far and how well.

Then have something like audioStream.play() that plays d stream and will never end unless something like audioStream.end() was called and stuffs like that

@paschaldev

It all depends on your audio provider and what protocols and codecs he is using to stream. As far as I see this is a paid service and I can not see in details how the audio stream is passed. My recommendation is to get familiar with the API provider that will stream the audio and once it is clear how you will receive the data to search for a solution to implement in your mobile app.
I will close this issue now - I can also recommend that you join us in our community slack channels where a lot of information can be obtained and shared with other users and NativeScript developers

p.p. Link to join the slack channels can be found here(green button named "slack")

@paschaldev Hi, I need to archive the same now. Did you come up with a solution and would you like to share pls?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings