I am making an audio player, i need to browse files/folders from device and add them to playlist (ListView). The most important for me is to UNDERSTAND what is going on, and how to do this. I think i need to get filenames and fill the ListView with it, but don't know how. Second qeustion is how to play these files in the playlist? Thank you!
You need to use the following steps
Query for the song, ContentResolver class to retrieve tracks on the device
Display the data extracted using Content Resolver in,list view.
Use MediaPlayer class to play audio and the MediaController class to
control playback.
Use a Service instance to play audio when the user is not directly interacting with the app.
Below I have mentioned very nice tutorial by TuPlus that covers everything of your question.
http://code.tutsplus.com/tutorials/create-a-music-player-on-android-project-setup--mobile-22764
Related
I need to implement Multi-track Audio Support feature in Sender application. Means, When user casts any video/movie on TV using Chromecast, then on sender application, user should be able to see all available audio tracks and choose desired audio track to cast on TV.
In Developers website, I saw Tracks API, in that MediaTrack object, which can be used to configure a track.
https://developers.google.com/cast/docs/android_sender#tracks
Here, I am not getting, how to fetch all available audio tracks from selected mp4 file? Can anyone provide the direction to work with this?
what will be the role of receiver application, regarding this?
I looked at given reference sample app. From that app, I am clear of how to set MediaTracks.
https://github.com/googlecast/CastVideos-android
I am not getting how to extract audio tracks from mp4 file, so that we can set them as MediaTracks?
Is this part needs to be done in receiver app?
Any help will be highly appreciated.
Thanks.
Currently, in the Cast SDK, there is no support for multiple embedded audio tracks in an mp4 file
Android developers,
I would like to know if it is possible to get, from inside my application, a reference to the last played media (audio or video) or viewed image.
I tried to get a list of MediaPlayer, but all I can get is the MediaPlayer from my own application context, not from the other applications. I could also get the current state for the MediaPlayer (if a file is playing or not), but thas all.
Is this possible?
thanks and regards
I don't think it is possible. For security reasons, an app cannot just view another app's data and there is no global 'recents' list (as in windows).
I want to know how a default media player works.Like how it scans all songs in sd card,how it displays them,so overall entire working on default media player.
I want this information so that I can compare it with my custom media player and check how fast my media player is working as compared to default one.I have tried searching internet but was not able to find some relevant information related to this.
Your question is very broad in perspective and hence, I will refer you to corresponding paths to get an understanding of the overall system.
First, the overall processing of media files starts from the Gallery application. Though not the entry point, ImageCacheRequest could be a good reference point to start the study, which shows how a cached image is read and rendered onto the screen.
Next, to understand how this thumbnail is generated, you will have to refer to ThumbnailManager.java which is invoked from camera, mms etc.
Thumbnail class internally employs MediaMetadataRetriever which is the main class for retrieving the thumbnail data.
MediaMetadataRetriever has a corresponding JNI implementation as shown here. The main function of interest is getFrameAtTime.
The most common implementation is StagefrightMetadataRetriever, which works on a simple principle. First, a MediaExtractor i.e. a parser is created which will sniff out the media-file type and create a corresponding parser entity as shown here. Next, the parser will then invoke a codec to decode the corresponding key frame at the requested time stamp and provide the image back as can be observed in extractVideoFramewithFlags.
Inside this function, a codec is created, frame is decoded, color converted and returned back to the caller which will transfer the same to the higher application.
In a nutshell, I feel your player will not come into picture and as long as the corresponding parsers and codecs are registered with the system, the thumbnails will be generated .
I want to know how a default media player works
There are dozens of "default media player" applications, as different Android devices ship with different "media player" applications, frequently written by their device manufacturers.
You are welcome to take a look at the implementation of the AOSP Music app, and there may be other open source media players that you can examine as well.
I want to query meta data from the external storage. That's pretty straight forward with the ContentProvider. But I also want to get the play count of the mp3 file.
I looked into projects like scrobble droid and subsonic but I didn't find a way to retrieve the Play Count if it's there. (e.g. Winamp supports it.)
Is there a way to get the PC if it's there?
You could manually read in the ID3 tags and check for a playcount attribute, but keep in mind, if this is for your own media player application, you'll have to modify the file each time it is played (load it, modify the ID3 tag, save the changes) which I imagine would be inefficient and a battery drain at best. Also, very few other media players actually DO this (Winamp, from what I see, seems to be one of the few), so it's not going to be an accurate playcount if played with, say, the stock media player, or any other media player which does not modify the ID3 tag.
Most media players that track playcounts (iTunes, Zune, etc.) do so by maintaining a database with playcount as an attribute. Obviously this is not portable between media players, but for your own implementation, I would suggest a database as your solution.
I faced the same problem but found some solution. So, android does not provide the data but music players could store this info. What I did:
* decompiled music app
* grep manifest file looking for provider
* profit
The solution is not perfect but I think there is no other ways to get this information on not rooted device.
Is there a way to play audio obtained from MediaStore through the use of the MediaPLayer, Or am I going in the completely wrong direction? I've looked and MediaStore.Audio so far but nothing is really helping me. I just need to know if I'm on the right track
First, I assume you have basic knowledge of querying a ContentProvider and working with Cursors. If you dont, I suggest you research it here
Once you have a basic knowledge of how to use a ContentProvider, query the URI MediaStore.Audio.Media.EXTERNAL_CONTENT_URI for the column Audio.Media.DATA, along with any other fields you need.
Let's say you put the returned cursor in yourCursor
String path = yourCursor.getString(getColumnIndex(Audio.Media.DATA));
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(path);
mp.prepare();
mp.start();
That's a very basic implementation. Get comfy with the android docs if you need to get fancy with it.
Have a look at the bundled music application source:
https://android.googlesource.com/platform/packages/apps/Music
List music using content providers
Use MediaPlayer in order to play the file you will get from the cursor
You also have examples on the android developer website: http://developer.android.com/guide/topics/media/index.html