Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stream an audio .pls in android

I'm making an radio like application that uses streaming. Here i need to stream the audio from a link (http://somedomain/some.pls).

I have created MediaPlayer and know how to play from an audio file. But don't know how to stream it from net.

EDIT : logcat i got while i used the following code

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

By log tag **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 tag **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 loops but no sound ..
What may be wrong..
Thank you.

like image 805
Jithin Avatar asked Dec 28 '22 01:12

Jithin


1 Answers


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

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

But remember to do the following:
1. Surround each of the statements above with try and catch statements and print copiously to LogCat. It will help debug easily.
2. Release the resources once you are done with it.

HTH,
Sriram

like image 181
Sriram Avatar answered Jan 26 '23 03:01

Sriram