iOS Question Problem with MediaPlayer component

Gianfranco Savino

New Member
Licensed User
I try to play .mp3 files on IOS. I use a button, when user choose a language button play different file.

I’ve this code:

Sub BtnPlay_Click
IfMain.sLang = "eng"Then
'MediaPlayer1.Stop
MediaPlayer1.Volume = 10
MediaPlayer1.Initialize(File.DirAssets,"i"&Main.sFileMP3&".mp3","MediaPlayer1")
MediaPlayer1.Play
EndIf
IfMain.sLang = "spa"Then
MediaPlayer1.Stop
MediaPlayer1.Volume = 10
MediaPlayer1.Initialize(File.DirAssets,"s"&Main.sFileMP3&".mp3","MediaPlayer1")
MediaPlayer1.Play
EndIf

IfMain.sLang = "cin"Then
MediaPlayer1.Stop
MediaPlayer1.Volume = 10
MediaPlayer1.Initialize(File.DirAssets,"c"&Main.sFileMP3&".mp3","MediaPlayer1")
MediaPlayer1.Play
EndIf
IfMain.sLang = "ara"Then
MediaPlayer1.Stop
MediaPlayer1.Volume = 10
MediaPlayer1.Initialize(File.DirAssets,"a"&Main.sFileMP3&".mp3","MediaPlayer1")
MediaPlayer1.Play
EndIf

End Sub

But when I click on this button app exit (close app without error)…..I think problem with mediaplayer component…..but I don’t know how to solve it.
 

Erel

Administrator
Staff member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Why don't you make your code more compact:
B4X:
Sub BtnPlay_Click
MediaPlayer1.Stop
MediaPlayer1.Volume = 10
 Dim prefixes As Map = CreateMap("eng": "i", "spa": "s", ...)
 Dim prefix As String = prefixes.Get(Main.sLang)
MediaPlayer1.Initialize(File.DirAssets,prefix &Main.sFileMP3&".mp3","MediaPlayer1")
MediaPlayer1.Play
End Sub
You are checking the log, right? Are you sure that there are no messages there?
 

Gianfranco Savino

New Member
Licensed User
Hi, I estract a summary of LOG:

Error occurred on line: 244 (appmain001)
Object was not initialized (AVAudioPlayer)
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
Anamnesi Multilingua -[B4IObjectWrapper object] + 180
Anamnesi Multilingua -[B4IMediaPlayer Stop] + 38
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
Anamnesi Multilingua +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1928
Anamnesi Multilingua -[B4IShell runVoidMethod] + 210
Anamnesi Multilingua -[B4IShell raiseEventImpl:method:args::] + 2002
Anamnesi Multilingua -[B4IShellBI raiseEvent:event:params:] + 1316
Anamnesi Multilingua __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 712
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
Anamnesi Multilingua main + 116
libdyld.dylib <redacted> + 2
)

But when I use MediaPlayer component, I'll initialize it:

B4X:
MediaPlayer1.Initialize(File.DirAssets,prefix &Main.sFileMP3&".mp3","MediaPlayer1")
MediaPlayer1.Play
what is the problem....I don't understand where is the problem.....

Thanks
 
Top