Download mp3 onto external sd card?

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Sorry for so many questions but I would like to know if B4A can download an mp3 file from a given web site address to the external micro sd card the user may have on their phone.

If yes, can you show me the coding needed?

Thanks.
 

admac231

Active Member
Licensed User
Longtime User
I've just had a go myself and I can't figure it out either. I do apologise :/

Edit: Scratch that. Pretty easy actually :)

B4X:
Sub Process_Globals
    Dim mp3Url As String
    mp3Url = "http://link_to_mp3"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    HttpUtils.CallbackActivity = "Main"
    HttpUtils.CallbackJobDoneSub = "JobDone"
    HttpUtils.Download("Job1", mp3Url)
End Sub

Sub Activity_Resume
    If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub UrlDone(Url As String)
    Log(Url & " done")
End Sub

Sub JobDone (Job As String)
    Select Job
        Case "Job1"
            If HttpUtils.IsSuccess(mp3Url) Then 
                Dim mp3 As InputStream
            mp3 = HttpUtils.GetInputStream(mp3Url)
            File.Copy2(mp3,File.OpenOutput(File.DirRootExternal,"mySong.mp3",False))
            End If
    End Select
    HttpUtils.Complete = False
End Sub
 
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Thanks so so so much for your help! :)

I will base my code on that.


I've just had a go myself and I can't figure it out either. I do apologise :/

Edit: Scratch that. Pretty easy actually :)

B4X:
Sub Process_Globals
    Dim mp3Url As String
    mp3Url = "http://link_to_mp3"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    HttpUtils.CallbackActivity = "Main"
    HttpUtils.CallbackJobDoneSub = "JobDone"
    HttpUtils.Download("Job1", mp3Url)
End Sub

Sub Activity_Resume
    If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub UrlDone(Url As String)
    Log(Url & " done")
End Sub

Sub JobDone (Job As String)
    Select Job
        Case "Job1"
            If HttpUtils.IsSuccess(mp3Url) Then 
                Dim mp3 As InputStream
            mp3 = HttpUtils.GetInputStream(mp3Url)
            File.Copy2(mp3,File.OpenOutput(File.DirRootExternal,"mySong.mp3",False))
            End If
    End Select
    HttpUtils.Complete = False
End Sub
 
Upvote 0
Top