Android Question Android 10 Media Player can't play Midi files

Michael Wenning

Member
Licensed User
Longtime User
my app based on MidiSystem2 and Midi Driver V2 Library from steve 05. Many thanks again to Steve for his outstanding work!!!
With the app the user creates midi files, which are then played with the media player. On Android 8 everything works perfect. With Android 10
devices is not possible to listen. i have done some research and compared the file content with a midifile created on the pc ( see attached files).
Is it possible to control the structure of the midifile with the libary? Or is there an easy solution?
Thank you for your answer
Michael
 

Attachments

  • MidiFileStudy.xlsx
    13.3 KB · Views: 160
  • MidiFiles.zip
    607 bytes · Views: 164

Michael Wenning

Member
Licensed User
Longtime User
I get MediaPlayer Error 1 (-2147483648).
The midifiles created on the pc in the same directory are played without problems.
Folder is MUSIK_FOLDER = File.DirRootExternal & "/Music/"
= /data/user/0/bla.bla.de/files/Music/
= Android > data > bla.bla.de > files > Music
There are no Android 10 permission problems.
If i play it with the App "MIDI Player" it shows no error but there is no sound output.
The same file in Android 8 Media Player or on PC with Windows Media player is playing whithout any problem.
 
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
I am not an expert on midi files.
90, ... ==> Note on
80, ... ==> Note off
I suspect that the Android 10 midi player interprets the many 80s as "note off" and therefore does not play the following 90 "note on" ...
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Folder is MUSIK_FOLDER = File.DirRootExternal & "/Music/" = /data/user/0/bla.bla.de/files/Music/
Those folders are NOT equivalent if that is what you mean. If you are in fact using File.DirRootExternal I assume you have requested PERMISSION_WRITE_EXTERNAL_STORAGE. If you are targeting SDK 29 you need this in the manifest in order to access File.DirRootExternal on Android 10.
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
see
android.jar / targetSdkVersion / minSdkVersion | B4X Programming Forum
 
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
Excuse me: you are rigth:
In #3 I have copied the wrong information:
Here is my code:

B4X:
' MW 27.04.2021
    If wifi.APIversion > 28 Then
        'MUSIK_FOLDER: /data/user/0/bla.bla.de/files/Music/
          
        MUSIK_FOLDER = rp.GetSafeDirDefaultExternal("Music")
        
#If DEBUG
        Log ( "MUSIK_FOLDER: " & MUSIK_FOLDER)
#end if
        
    Else
        MUSIK_FOLDER = File.DirRootExternal & "/Music/"
    End If
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I am not an expert on midi files.
90, ... ==> Note on
80, ... ==> Note off
Midi is a sequential protocol, so if a note on follows a note off, then it will play. Some midi files use a note on message with a volume value of 0 as a note off. I don't have an android 10 device to test the files on.

Within the midisystem2 library, you can edit the midi file as you like.

Check if you have any controller messages in the file, there are many possible controllers and some will mute the sounds.

Does it play the files created on a PC?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Comparing your example files by playing them on my PC, I notice that the notes in the F5_bb.mid file are very short, you could try making the notes longer and see if it makes a difference. It's not a solution, but just a suggestion to get to the problem.
 
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
Does it play the files created on a PC? The same file in Android 8 Media Player or on PC with Windows Media player is playing whithout any problem.
In the attached excel file there is the actuell byte code with my interpretation. I have marked the ones which i know but some i don't know.
Tommorrow i check, if i can influence the midi file output with the midisystem2 libary.
 
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
Long/short files were my first attempt at improvement.
It makes no difference. To make the files comparable, I recorded both files (PC and Android 10 created) with only 3 notes.
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Hi Miachel, I checked your file and hope this helps:
  • 3a? 3f?: this is the number of bytes from next byte after this 3a/3f to the end of the track
  • unknown: F5_bb.mid: 9b 80 80 80 81 5c: delta time. I think this is NOT correct as it is a very large number, I guess some midi parser may be able to correct this but some may not. All following similar patterns between 90 XX XX and 80 XX XX are same delta time and they are also too large to be correct. I haven't tried the midi lib but maybe you could check the delta time generation.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
How are you actually saving the file?
 
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
B4X:
MUSIK_FOLDER = rp.GetSafeDirDefaultExternal("Music")
FilePath = MUSIK_FOLDER
MidiSystem_Static.WriteSequence(Starter.glSeqr.GetSequence,1,FilePath,FileName)

I have checked with

B4X:
MidiSystem_Static.WriteSequence(Starter.glSeqr.GetSequence,0,FilePath,FileName)

but i get the same result
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I'll try and take a look at the code over the weekend.
 
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
Steve, thank you very much for your help!!!

Attached midi file (F5_bb_short.mid) is made from F5_bb.mid file (app created). It is edit with an online hex online editor.
I eliminate all unknown bytes and now it works perfect with Android 10 MediaPlayer. The byte code you find in the attached Excel file.
 

Attachments

  • F5_bb_short5.zip
    219 bytes · Views: 127
  • MidiFileStudy_V2.xlsx
    13.7 KB · Views: 128
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
Steve, I took your piano midi example and minimally mocdified it for Android 10 needs. Maybe this is a good start for your investigation?
 

Attachments

  • Piano&FullMidiLib.zip
    367.3 KB · Views: 141
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hi Michael,

I have looked at this issue over the weekend, but I can't really see a solution without knowing why it works on Android 8 but not on android 9/10. I can't find any reference to major changes in the way android plays midi files. Although there is very little information about it on the internet.

I am reluctant to change the library in any way as it still works on older devices and PC.

I have uploaded the full code for the library to the library thread in case you want to investigate further.

If we can find out what has changed on Android, there may be a chance to get it working without risking it failing on the other devices.

Steve
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Hi stevel05, thanks for midilib source code. As I assumed something wrong in the delta time writing I checked the Private Sub WriteVarInt(Value As Long) As Int func in MidiFileWriter.bas.

I am not sure what input Value is but if it is the delta time then maybe the conversion is not correct. 65535 should be converted to 0x83 FF 7F. Please check the attached code I made. The left is from midilib reproducing the very large delta time error and the right is from another midi code I modified.

c.PNG
 

Attachments

  • MidiTimeTestBed.zip
    2.7 KB · Views: 130
Upvote 0

Michael Wenning

Member
Licensed User
Longtime User
Thank you Steve, thank you KimStudio!
I am starting to understand how the midilibary works.
I am currently investigating how the deltatime is composed.
When I get further, I will report back and share the results for discussion.
Best regards
Michael
 
Upvote 0
Top