Android .pls audio stream

I am making a radio application using streaming. Here I need to transfer the audio from the link ( http://somedomain/some.pls ).

I created MediaPlayer and can play from an audio file. But I do not know how to sink it from the network.

EDIT: I got logcat while I used the following code

 MediaPlayer mp = new MediaPlayer(); mp.setDataSource(http://somedomain/some.pls); mp.prepare(); mp.start() 

By Magazine **MediaPlayer**

  02-15 05:50:11.761: VERBOSE/MediaPlayer(23715): constructor 02-15 05:50:11.761: VERBOSE/MediaPlayer(23715): setListener 02-15 05:50:11.761: INFO/MediaPlayer(23715): uri is:http://some:444/sdfd.pls 02-15 05:50:11.761: INFO/MediaPlayer(23715): path is null 02-15 05:50:11.761: DEBUG/MediaPlayer(23715): Couldn't open file on client side, trying server side 02-15 05:50:11.765: VERBOSE/MediaPlayer(23715): setDataSource(http://some:444/sdfd.pls) 02-15 05:50:11.777: VERBOSE/MediaPlayer(23715): prepare 02-15 05:50:13.105: ERROR/MediaPlayer(23715): message received msg=3, ext1=0, ext2=0 02-15 05:50:13.105: VERBOSE/MediaPlayer(23715): buffering 0 02-15 05:50:13.105: ERROR/MediaPlayer(23715): callback application 02-15 05:50:13.105: ERROR/MediaPlayer(23715): back from callback 

By Log **PlayerDriver**

 02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): constructor 02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): OpenCore hardware module not found 02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): start player thread 02-15 05:50:11.765: VERBOSE/PlayerDriver(2393): startPlayerThread 02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): InitializeForThread 02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): OMX_MasterInit 02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): OsclScheduler::Init 02-15 05:50:11.769: VERBOSE/PlayerDriver(2393): CreatePlayer 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): AddToScheduler 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): PendForExec 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): OsclActiveScheduler::Current 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): StartScheduler 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): Send player code: 2 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): CommandCompleted 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): Completed command PLAYER_SETUP status=1 02-15 05:50:11.777: INFO/PlayerDriver(2393): PlayerDriver::isProtectedFile(http://some:444/sdfd.pls) 02-15 05:50:11.777: VERBOSE/PlayerDriver(2393): File EXT is : .pls 02-15 05:50:11.777: ERROR/PlayerDriver(2393): PlayerDriver::it is a not Protected file 02-15 05:50:11.781: VERBOSE/PlayerDriver(2393): Send player code: 3 02-15 05:50:11.781: VERBOSE/PlayerDriver(2393): handleSetDataSource 02-15 05:50:11.781: VERBOSE/PlayerDriver(2393): handleSetDataSource- scanning for extension 02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): CommandCompleted 02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): Completed command PLAYER_SET_DATA_SOURCE status=1 02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): Send player code: 6 02-15 05:50:11.800: VERBOSE/PlayerDriver(2393): release string is 2.2 len 3 02-15 05:50:13.101: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 34 02-15 05:50:13.101: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 19 02-15 05:50:13.124: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20 02-15 05:50:14.511: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20 02-15 05:50:16.509: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20 

This 02-15 05:50:16.509: VERBOSE/PlayerDriver(2393): HandleInformationalEvent: 20 loop, but no sound.
What could be wrong ..
Thanks.

+4
source share
4 answers


You can use the file streaming capabilities available in the MediaPlayer class to do this.
I have not tested the following code, but it should be something in these lines:

 MediaPlayer mp = new MediaPlayer(); mp.setDataSource(http://somedomain/some.pls); mp.prepare(); mp.start(); 

But do not forget to do the following:
1. Equip each of the above statements with try and catch try and print them sadly on LogCat . This will help to debug easily.
2. Release resources as soon as you are done with it.

NTN
Sriram

+4
source

Android's mediaplayer api supports streaming .pls file, but the API is not the best option, and the documentation is not very good. The life cycle diagram provided in the official documentation provides valuable information, but can be confusing at first glance.

Example code snippet:

 MediaPlayer mp; mp=MediaPlayer.create(getApplicationContext(),Uri.parse(url)) Example url of .pls file http://50.xx.xxx.xx:xx40/) mp.start(); mp.pause(); mp.release() (or mp.reset() as applicable) 

http://developer.android.com/reference/android/media/MediaPlayer.html#create(android.content.Context , android.net.Uri)

There are listeners / callbacks in the MediaPlayer api, but for application developers working with audio streaming, it's really problematic.

A static constructor used in the code snippet / best approach for creating a media object with a URI (for example, http-url with host and port) is proposed. But the callback functions cannot be used by the developer, because the preparation is called by the constructor itself.

The created object can be played / stopped in the asyn stream (AsyncTask api).

The official documentation on android does not give any "method of obtaining" to get the status of a media player.

I welcome Android app developers to talk about this;

and I want the framework developers to provide more accurate documentation - how much it supports or what the relevance and vision of the Google Inc and Android development team are in the Mediaplayer API for streaming audio with URLs.

If someone needs help from me or share your experience, let me talk about MediaPlayer api for audio streaming @ /fooobar.com / ... or the Android developers blog (android-developers.blogspot.com).

Relationship Sri Ramakrishna Program Manager and Android Developer @New Mek Solutions, Hyderabad.

+4
source

You can try to download the pls file, analyze the urls that are there and put them in MediaPlayer.

+1
source

Man, try two things:

1: code

 mediaPlayer = MediaPlayer.create(this, Uri.parse("http://vprbbc.streamguys.net:80/vprbbc24.mp3")); mediaPlayer.start(); 

2: .pls file

This URL is from the BBC as an example. It was a .pls file which I uploaded on linux using

 wget http://foo.bar/file.pls 

and then I opened vim (use your favorite editor;), and I saw the real URLs inside this file. Unfortunately, not all of the .pls are plain text.

enjoy!

+1
source

Source: https://habr.com/ru/post/1339009/


All Articles