iOS Question MediaPlayer doesn't play mp3 files

stephane..blusson

Member
Licensed User
Hi, I am developing a chat with audio messaging and I faced a problem. I can download the file from the server using FTP, but I cannot play it, I have the error here:

B4X:
Mp.Initialize(File.DirDocuments, audiomessagefilename, "MP")

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

P.S. I can see the file in the directory using this code
B4X:
        For i = 0 To File.ListFiles(shared).Size - 1
            Log(File.ListFiles(shared).Get(i))
        Next

maybe someone came across this problem and can help me
 

stephane..blusson

Member
Licensed User
Thanks for the answer

This looks like a pretty good solution. But the problem is that audio messages are stored on the server, where they can be sent from an android device and there will be no possibility to edit the audio. Maybe mediaplayer isn't the only solution to this problem?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Doubt in success, but you can try AVPlayer, which allows to play URL.

Declare global variable
B4X:
Private player1 As NativeObject

Add, for example, to Application_Start
B4X:
    player1 = CreatePlayer("https://<path>.mp3")
    player1.RunMethod("play", Null)

In addition add Erel's subroutine
B4X:
Sub CreatePlayer(url As String) As NativeObject
   Dim u As NativeObject
   u = u.Initialize("NSURL").RunMethod("URLWithString:", Array(url))
   Dim player As NativeObject
   player = player.Initialize("AVPlayer").RunMethod("alloc", Null).RunMethod("initWithURL:", Array(u))
   Return player
End Sub
 
Upvote 0

stephane..blusson

Member
Licensed User
Thanks for the answer. I decided to test your assumption
I uninstalled the application and tried to download these files again via FTP. The download was successful (Success = True in FTP_DownloadCompleted).
Displayed the size of this file in the audio playback function

B4X:
Log(File.Size(shared, "!AudioMsg-1633353000129.mp3"))

and it is 3672
 
Upvote 0

stephane..blusson

Member
Licensed User
Is that the correct size? Looks a bit small.
Thanks for the advice. I downloaded a file from the server with a size of 62451. I thought there might be a problem with the file name, because it starts with a "!" But the error has not gone anywhere. I tried to upload the file directly to the server and then download it and play it on Ipad and everything worked, but my audio messages from android break on the initialization of the Media Player.

P.S. I tried to download the file from the server to the pc and it plays without problems
 
Upvote 0
Top