[Android]play sound file

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

[Android]play sound file

Postby Lena » Mon Jun 06, 2016 7:19 am

How play a sound file an android device?
Lena
BCBJ Master
BCBJ Master
 
Posts: 525
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]play sound file

Postby Lena » Mon Jun 06, 2016 11:40 am

I found sample TMediaPlayer
Code: Select all
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR) || defined(__ANDROID__)
   MediaPlayer1->FileName =
      IncludeTrailingPathDelimiter(System::Ioutils::TPath::GetDocumentsPath()) +
      "soundsample.mp3";
#else
   MediaPlayer1->FileName = "soundsample.mp3";
#endif
   MediaPlayer1->Play();
Lena
BCBJ Master
BCBJ Master
 
Posts: 525
Joined: Sun Feb 06, 2011 1:28 pm

Re: [Android]play sound file

Postby rlebeau » Mon Jun 06, 2016 12:33 pm

Lena wrote:I found sample TMediaPlayer


Why are you using an absolute path only on iOS/Android, but using a relative path on other platforms? You should be using an absolute path on all platforms. Never rely on relative paths, you have no guarantee of what base path they are actually relative to at runtime. You can't guarantee they are always relative you your executable's installation path.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1457
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 10 guests