Delay when playing files with mediaplayer in loop mode

drskeggia

New Member
Licensed User
Longtime User
Dear Staff. really great environment for Android devices.

One question about Mediaplayer: i am playing some short mp3 or wav files (about 3 secs length)

i set the Looping to TRUE the software "loops" the file

but there is a half second delay from the end of each playback, and the beginning of the next one.

is there a way to avoid the gap , the "silence" between the playbacks when looping?

Thank you Roberto
 

JiggyMan

Member
Licensed User
Longtime User
is there a way to avoid the gap , the "silence" between the playbacks when looping?

Thank you Roberto

Perhaps the gap is caused by silence at the end of the mp3 or wav file(s).

One of the first things I developed with B4A is my own mp3 player, including a repeat mode, using the media player. The only time I've noticed a delay in repeating is when there is silence at the end of a file. Hence, in reality, there is no "delay". It simply finishes playing the file, silence included, prior to repeating it. Check the file(s) involved and see if that may be your situation.

If I find the silent portion too lengthy in any given file, I have some audio editing software I use to truncate it.

Being as this is my first time posting, I'd like to commend Erel and everyone else involved in developing such a fine product. I have been having fun programming my phone. :sign0098:
 
Upvote 0

drskeggia

New Member
Licensed User
Longtime User
Thank you for your response.

I am sure the file has no "space" before or after.
before loading the MP3 file inside my software , i checked with some
loop/player for pc
to check if loop was ok , and it was perfect.

then i tried now using the mediaplayer tutorial code ,
exactly the same

it seems to be a delay related to the compiler

i have tested on virtual device and on a Galaxy Nexus

the first written code it was :

dim MP as mediaplayer

mp.initialize
mp.Load(File.DirAssets, "blur.mp3")
mp.looping = true
mp.play


blur.mp3 is 4 secs file , 100k

tried using file in .wav format , the same

don't have other ideas....


you said you made a mediaplayer with loop working correctly
could you post the "core" code for playing?

Thank you
 
Upvote 0

JiggyMan

Member
Licensed User
Longtime User
you said you made a mediaplayer with loop working correctly
could you post the "core" code for playing?

I did say that. And, after reviewing my code, I realize I inadvertently misled you. My apologies. It has been awhile since I've written the program.

In fact, what I did was to handle the repeat mechanism myself in code. I remember now I did that because it was simpler for me to differentiate between "repeat song" and "repeat list". Perhaps you could try coding your own repeat mechanism to see if it helps.

The following is in a service module. I'm not sure how much of this will make sense with it being "taken out of context", so to speak, so I will try to clarify some things.

1) Subs/Global Variables: "RepeatMode" is a variable that gets set whenever the Repeat button is pressed. It cycles through REPEAT_NONE, REPEAT_SONG, REPEAT_LIST. "PlaySong" is a separate sub which does the actual loading/playing of the mp3 file and setting the notification status. "SongIndex" is the list index of the current song. "Status" is a notification to show the Artist/Title of the song currently playing. "tUpdate" is a timer used to update the current position/duration of the song while playing.

2) Even if I haven't loaded a playlist, the player actually sees a playlist at all times, meaning whatever songs I have manually queued to be played are in list format to the player - even if it's a list containing only one song.
B4X:
Sub Player_Complete
   If RepeatMode = REPEAT_SONG Then
      PlaySong ' repeat current song
   Else If PlayList.Size > (SongIndex + 1) Then
      SongIndex = SongIndex + 1 ' play next song
      PlaySong
   Else If RepeatMode = REPEAT_LIST Then
      SongIndex = 0 ' replay list from start
      PlaySong
   Else
      Status.Cancel(1)
      Main.tUpdate.Enabled = False
      If IsPaused(Main) Then
         Main.ShowDisplay = False
      Else
         CallSub2(Main, "SongDisplayVisible", False)
      End If
   End If
End Sub

HTH
 
Upvote 0
Top