iOS Question Download a MP3 file and play it

Humberto

Active Member
Licensed User
I´m trying to download a "mp3" file and then play it

The request
B4X:
        job_evento.Initialize ("mp3", Me)
        job_evento.Download ( "http://www.consulta10.com.br/ttm/voz/audio.mp3")      
        job_evento.GetRequest.SetContentType ("audio/mpeg")

The jobdone

B4X:
        Select Job.JobName
            '        Case "Job_Indicacao"
            ''            ToastMessageShow ( xresp, True )
            '            CallSub2 ( Main, "Back_Indicacao", xresp )
            Case "Job_Token"
                xresp = Job.GetString
                Msgbox (xresp, "Retorno")
            Case "Job_File"
                xresp = Job.GetString
                Msgbox (xresp, "File")
            Case "mp3"
                Dim xOutput As OutputStream = File.OpenOutput (File.DirTemp, "voz.mp3", False)
                File.Copy2(Job.GetInputStream, xOutput)
                xOutput.Close
                If  File.Exists  (File.DirTemp, "voz.mp3" ) Then
                    Log ( "file exists")
                End If
                MyPlayer1.Initialize ( File.DirTemp, "voz.mp3", "MyPlayEnd")
                MyPlayer1.Looping=False
                MyPlayer1.Volume = 1
                MyPlayer1.Play
        End Select

I get an error when I try to initialize the file ( theis line MyPlayer1.Initialize ( File.DirTemp, "voz.mp3", "MyPlayEnd")

The log ( "file Exists" appear

The log

Error loading file: Error Domain=NSOSStatusErrorDomain Code=1685348671 "(null)"
 

Humberto

Active Member
Licensed User
I did some test.

I can download a zip file with an "mp3" file zipped.

Then I unzip in a Iphone and then I uploaded this file to my server and the file is correct and still play song.

I just can´t play using Media Player.

How Spotfy do ? It download the file and then play locally.


The problem is that VideoView doesn´t start playing in background but MediaPlayer do, so I´m trying to download the file to play locally
 
Upvote 0

Humberto

Active Member
Licensed User
If I put a "mp3" in a file tab MediaPlayer play the song.

B4X:
        MyPlayer1.Initialize(File.DirAssets, "sirene.mp3","MyPlayEnd")
        MyPlayer1.Looping=False
    '    MyPlayer1.Volume = 1
        MyPlayer1.Play

Works.

What other extensions MediaPlayer works ?
 
Last edited:
Upvote 0
Top