Android Question MediaPlayerStream with Post before

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Anyone know how I can use the MEDIAPLAYERSTREAM or something like that when I need the POST some data to create a sound and download automaticly?

Let me explain:

I have a service API in my company that create a sound automaticly, but I need send some parameters in JSON format, like type of voice, message, etc.

*************************************************************************
Dim In As InputStream = File.OpenInput("/sdcard/Download/","File.json")
Dim size As Long = File.size("/sdcard/Download/","File.json")
Dim request as HttpRequest
request.InitializePost("http://test.creawavestudio.com/pocpsa/api", In, size)
request.Timeout = 60000
objHttpClient.Execute(request, 1000)
*************************************************************************

But when pass into event objHttpClient_ResponseSuccess

and I get que File and save to .MP3 like this
Response.GetAsynchronously("ResponseCrea", File.OpenOutput("/sdcard/Download/","File.mp3", False), True, TaskId)
Work very well, but is not STREAMING, is Download and Play with Media Player

and the MEDIAPLAYERSTREAM is work only with a URL of the MP3

How I can play this, without wait the entire download?

Please help Me!
 

gehrlekrona

Member
Licensed User
Longtime User
Did you ever get this to work? I am trying to kind of do the same. I need to query a database and get the name of the MP3 file. After that I need to stream that file but I don't want to download it. Anybody that can help? I have tried Httpclient but that didn't work. I was told to use Httputils2 instead but I only have version 1.8 so I can't use that one. Need to use Httputils instead but can't figure out how to do it :(
 
Upvote 0

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hello gehrlekrona,

Yes I did, the easy way to do this is create a little service to play a URL with mp3, look

In your activity, call like:

if TocandoMusica.IsPlaying = False Then
TocandoMusica.URLMusica = "http://www.ultraje.com/mp3/rebelde.mp3"
StartService(TocandoMusica)
end if

and create a service with this name "TocandoMusica"

#Region Service Attributes
#StartAtBoot: False
#End Region

Sub Process_Globals

Dim URLMusica As String
Dim n As Notification
Dim mediaPlayer1 As MediaPlayer
Dim mp As MediaPlayerStream
Dim IsPlaying As Boolean

End Sub
Sub Service_Create

mp.Initialize("mp")
mp.Load(URLMusica)
Log("Musica = " & URLMusica)

End Sub
Sub mp_StreamReady
Log("mp_StreamReady")
mp.Play
IsPlaying = True
End Sub
Sub mp_StreamError (ErrorCode As String, ExtraData As Int)
Log("Error: " & ErrorCode & ", " & ExtraData)
ToastMessageShow("Error: " & ErrorCode & ", " & ExtraData, True)
IsPlaying = False
End Sub
Sub mp_StreamBuffer(Percentage As Int)
'Log(Percentage)
End Sub

Sub Service_Start (StartingIntent As Intent)
n.Initialize
n.OnGoingEvent = True
n.Sound = True
n.Vibrate = True
n.Icon = "icon"
n.SetInfo("Ultraje > " & URLMusica, "", Main)
n.autocancel = False
n.Notify(1)
End Sub

Sub Service_Destroy
mp.Stop
n.Cancel(1)
IsPlaying = False
End Sub
 
Upvote 0
Top