I am developing an Android application in which I am showing a ListView of mp3 files from the sd card.
Now what I want is that when user clicks on any of the mp3 files it should start playing there on the same Activity. The code which I am using presently is not working for me to play audio files.
My code:
Uri uri = Uri.parse("/sdcard/music/sample.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
But this is something that I want. This is a screen Shot form android gingerbread
see this link here is a good example of getting all the music files and show in list and play when you click any item...
Display MusicList and play on itemClick
Another link
I suppose you should use another approach in case you want audio played in the same activity. I'd better initialize MediaPlayer object in this activity or as a background service.
In case of any questions feel free to ask.
UPDATE 1
In general case as I said you either need the MediaPlayer object in Activity or Music Service.
Now lets talk about controls.
You can simply put into your layout the block with controls and show/hide it when needed. MediaPlayer provides several convenient callbacks, so you will be able to update progressbar.
So, sum up:
Include controls into layout.
Include MediaPlayer into activity or make it work as a Service.
Bond controls to player.
???
PROFIT
Related
I am working on a Music player. I want to add default Equalizer ( Sound effect) in my music player app. I successfully add it to my player app but sound effect not working on the media player of my android app. No effect when I change Jazz, Pop, Rock, Folk etc.. how to attach it which current media player in our Android app.
I open it with Intent
val intent = Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL)
if (intent.resolveActivity(packageManager) != null)
{
startActivityForResult(intent, 1234)
}
This link has quiet a lot of information on how to create an equalizer from scratch
https://www.101apps.co.za/articles/perfect-sound-using-the-equalizer-effect-a-tutorial.html
If this is not what you are looking for, perhaps a bit more info could be helpful.
To clear the basics: make sure you are creating the equalizer and attaching it to the media player. Also make sure you are setting up the UI by calling the setupEqualizerFxAndUI.
Hope this helps.
I want to develop video player like dailymotion app. The main thing that i want to achieve is it's rotation behaviour and full screen button action. When user rotate device or tap on full screen button the video player goes to full screen and video play continue without any intruption.
Currently i am using video view widget for Stream video. but when user rotate device. the video stop and video view activity reload and video view intilize again and then video play.
So please suggest me solution of this problem. Thanks in advance.
You can use below flags when registering your activity in manifest file
android:configChanges="orientation|screenSize|keyboardHidden"
and then in you activty class just override "onConfigurationsChanged()" method so that your activity won't restart when orientation changes.
One thing that you can try is to save video current position in "onConfigurationChanged()" so that after rotation when VideoView reinitialize itself you can continue to play video from that position.
ues ExoPlayer as base class and extend it as your own Custom Player. these issues are handled here. this is available on official android developer site
http://developer.android.com/guide/topics/media/exoplayer.html
I have an app that on ImageButton click it opens the Gallery intent from where you can either choose some pictures OR take another one using the Camera intent.
My question is: I have made a camera layout that I would like to use instead of the one from the gallery intent. How could I use my custom layout instead of the basic one? Thanks
As far as I understand, you need Intent.ACTION_PICK
See details here: http://sudhanshuvinodgupta.blogspot.com/2012/07/using-intentactionpick.html
I open a video in my application with an intent to the default player. It shows a gallery in the top left that would go to the gallery for the device which I don't want. Is there a way to customize it so that either that icon will fire the equivalent of the back button OR just remove it altogether?
I was thinking there were params in the intent or something that would be interpreted by the activity.
Goal: I want to be able to launch default player without the top nav bar. I feel it is something that i should just create my own VideoView for, instead of using a default player. I just didnt want the gallery button to point back to the gallery. Feel that might be some confusion.
I havent seen anything that told me of optional parameters i could pass into the video activity.
I have an array of times that correspond to events in a recorded video. These times inflate a list. When a list entry is selected, I want the video to open to the time selected
Right now, the following code only opens the video at the beginning of the video.
Uri video = Uri.parse(Environment.getExternalStorageDirectory()+"/recordedMedia/" +eventName+ ".mp4");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.setDataAndType(video, "video/*");
startActivity(intent);
Ideally directly at the specified time would be best, although starting at the beginning, then skipping to the specified time, would work too, if it is fairly quick.
I'm working with Android 2.2, API 8
Maybe you could use the seekTo() method from the MediaPlayer object?
I haven't tested this and you'll need to add in exception handling, but you could go for something along these lines:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(Environment.getExternalStorageDirectory()+"/recordedMedia/" +eventName+ ".mp4");
mp.prepare();
mp.seekTo(/*a time*/);
I would recommend using the MediaPlayer class in your own code. The way you've done it will use the default player for the media type or one of the user's choosing. Even if you could figure out how to make that particular media player start from a certain position, you have no chance of getting it to work with the wide variety of players in use, including some devices where the Android defaults have been replaced with OEM variants.
Create your own activity using a MediaPlayer and use seekTo() to start from your desired position. There are loads of examples on the web.
Cheers