I have image is my Draw able folder.When I call this image I want to play an audio also which is in my raw folder.can I do this how??please help me.
You can achieve by creating image button and put image on it. and onClick of that button you can play the music using MediaPlayer api.
Refer this : http://developer.android.com/guide/topics/media/index.html
Example code for Play audio from Raw folder
: http://www.barebonescoder.com/2010/06/android-development-audio-playback-safely/
you can write this code at onResume:
MediaPlayer mp = MediaPlayer.create(getApplicationContext(),
R.raw.name);
mp.start();
while (mp.isPlaying()) { // donothing
}
;
mp.release();
Related
I want to make a application in which i play the .mp3 file
i play the sound by selecting it from raw or asset folder which is hard coded in code.
But i want that user pick any mp3 file anywhere from their android phone and make play it
Can any one help me
Thanks in advance
MediaPlayer mediaPlayer= MediaPlayer.create(this, R.raw.song);
mediaPlayer.start();
int duration = mediaPlayer.getDuration();
int current_position = mediaPlayer.getCurrentPosition();
mediaPlayer.pause();
Great tutorial on Media Playback through MediaPlayer:
http://www.tutorialspoint.com/android/android_mediaplayer.htm
I need to create only one media player object Mediaplayer mp = new Mediaplayer();
Using this I need to play multiple audio files one after the other for that i am using handler
and getting the duration.
If i create multiple media player objects it shows error(1, -17)
I also need to display images related to audio files.
Did you rule out SoundPool?
http://developer.android.com/reference/android/media/SoundPool.html
It typically good for short audio clips.
Implement the OnCompletionListener and register it with your MediaPlayer instance.
After the media has been played out it will call this callback method onCompletion
void onCompletion(MediaPlayer mp){
//Here you stop it.
mp.stop();
//Reset the data source path to the new file
mp.setDataSource(<uri>);
mp.prepare(); // or mp.prepareAsync();
// start the mediaplayer after the prepare has completed.
}
Release the mediaplayer instance once you are done playing all the files.
Hi there I'm an android and java newbie and is wondering if there is a better way of doing the following:
I currently have 250 short audio files (.3gp) that i put inside my res/raw folder and based on a certain condition, I want to play certain audio file. For example if the text of the button that is being clicked is the word "and", I want to play the and.3gp sound file.
The following is the code that I use to accomplish what I want to do:
if(word.equals("No"))
{
MediaPlayer mp = MediaPlayer.create(HomeActivity.this,R.raw.no);
mp.start();
mp.setOnCompletionListener(listener );
}
else if(word.equals("And"))
{
MediaPlayer mp = MediaPlayer.create(HomeActivity.this,R.raw.and);
mp.start();
mp.setOnCompletionListener(listener );
}
.....
The above code is working fine so far but I'm wondering if I can do this without having a 250 else if condition. Is there a way to pass in the audio file to MedialPlayer.Create by file name via Uri? If yes, how do I do it? Thank you.
You can make a hash function that maps a string key to the uri
Loop through all your files in your raw folder and remove the file extension, then test against that.
In android, is there a way I can conditionally play a small .wav file when a layout is displayed to the user (on load), like so:
if (randonGen == 3) {
//play small wav sound here
mTheMessage = (TextView) findViewById(R.id.resultText);
mTheImageButton = (ImageButton) findViewById(R.id.face_image);
mTheImageButton.setBackgroundDrawable(bitDraw);
mThePicture.setImageBitmap(cameraBitmap);
}
Where the code to call my sound.wav from my assets folder is called and played?
Actually - I figured out that a simple Media Play will do the trick with small wavs:
MediaPlayer mp = MediaPlayer.create(this, R.raw.your_wav);
mp.start();
android.media.SoundPool looks like it will do what you want.
how do i display videos retrieved from resources in my android application ?
MediaPlayer mp = new MediaPlayer();
mp = MediaPlayer.create(context, R.raw.vid);
mp.start();
i have placed a vid.3gp file in my res/raw folder..
i am getting NullPointerException.. what changes do i need to make
why so??
do we need something called as Surface Holder or something similar ?
using the MediaPlayer you should be able to play video