1

I having problem to play sound files on android. Please see below my code as it works fine up to nearly 200 times but after that sounds doesn't come up.

I receive java.lang.RuntimeException: setDataSource failed: stastus = 0x800000000.

And sometimes it also gives me error java.oi.IOException: Prepare failed.: status=0x1.

Please let me know if the code below has any problem or if anyone experienced this issue please help.

Thanks

             MediaPlayer1.FileName := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetPublicPath,'sound/Warning.3gp');
             if MediaPlayer1.Media <> nil then
             begin
                 MediaPlayer1.Play;
             end;

Note: I have removed the MediaPlayer1 from the project and tried to create run time and destroy after but ended up with exactly the same result.

  if(lMode=2) and (myQuery.RecordCount=0) then
  begin
      var mp : TMediaPlayer;
      mp:=TMediaPlayer.Create(Self); // or AParent if it is a passed variable
      mp.Parent:=Self; // (AParent) you must set its parent

      mp.FileName := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetPublicPath,'sound/NOTFOUND.3gp');
      if mp.Media <> nil then
      begin
         mp.Play;
      end;
      mp.Free;
   end;
mesutuk
  • 402
  • 3
  • 17
  • If you are getting sqlite errors, then there's something else happening in your app, that is what is putting your app into an unstable state and which is consequently preventing the sounds from being played. Fix the sqlite error, and your sounds will probably be played. – Freddie Bell Jun 06 '22 at 14:40
  • "_sqlite error messages_" - which exactly? The **message** is meant to be read by a human, not some other process. – AmigoJack Jun 06 '22 at 14:52
  • I get "java.oi.IOException: Prepare failed.: status=0x1.". But I get this error only if I play a sound. rest of the application doesnt get any sqlite error at all. – mesutuk Jun 06 '22 at 14:56
  • 3
    Why do you think this is a sqlite error message? – Freddie Bell Jun 06 '22 at 16:39
  • You are right , it has nothing to do with sqlite as it was just a coincidence. I have edited my question. – mesutuk Jun 06 '22 at 19:42
  • 1
    Surely you want to `Free` (not `Destroy`) the TMediaPlayer only after it has finished playing? Having said that, there's no event to signal when it has finished playing anyway. I had similar issues with playing sounds on Android and ended up writing my own implementation. For "short" sounds (such is in a game etc), there's a demo [here](https://github.com/DelphiWorlds/Kastri/tree/master/Demos/SoundPlayer), which uses the TSoundPlayer class [here](https://github.com/DelphiWorlds/Kastri/tree/master/Features/SoundPlayer) – Dave Nottage Jun 06 '22 at 22:37
  • 1
    For playing "longer" audio, there's TAudioPlayer [here](https://github.com/DelphiWorlds/Kastri/tree/master/Features/AudioPlayer) (no demo yet) – Dave Nottage Jun 06 '22 at 22:38
  • Thanks Dave.. Demo was fantastic as it does exactly what I need. – mesutuk Jun 06 '22 at 23:29

0 Answers0