[Q] Default media player - Android Software Development

Hello everyone,
i'm trying to do a podcast software, but i can't find a way to play music througth the default media player.
What should i use?
I use now Mediaplayer() but it has no user interface (no pause, forward ...) which is pretty annoying.
Thank you for your answers!

Have you looked at the MediaController class:
http://developer.android.com/reference/android/widget/MediaController.html

By now, i used another method with Intent.
String path = "/sdcard/feed/"+ title+"/"+fileName + ".mp3";
Intent myIntent =new Intent(android.content.Intent.ACTION_VIEW);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myIntent.setDataAndType(Uri.parse("file://"+ path),"audio/*");
startActivity(myIntent);
Which actually works for mp3s.
I am looking for the basic Android downloader (the one used by the market for example)
Do you know how to use it?
Thank you a lot

So you want to download the file first to the sdcard, then play it by launching the default program for MIME type "audio/*"? seems convoluted. The MediaPlayer object will do all this for you in streaming mode and the MediaController class will give you a nice interface.
Otherwise, I don't know what you mean by "basic Android downloader".

Related

Coding to Play streaming PLS (ShoutCast)

Hey folks, I'm trying to write an app to play a PLS stream from a ShoutCast server, any advice? I'm able to stream standard MP3s using the MediaPlayer class, but it doesn't seem to work with PLS files.
Hi,
a PLS file is a playlist file not an actual media(sound/video) file, you can open it with your favorite text editor. To be able to listen to a stream you need to be able to decode the media type(AAC,MP3,WMA,...) thats what codecs are for
Yeah, I know, I tried using the adress in the .pls but it wasn't playing/nor throwing an error. I was pretty sure it was a valid codec being used (it works fine with a static mp3 path), so I guess I'll have to check with the settings on the ShoutCast server.
Thanks for the reply.
I'm interested in that idea of being able to listen to streams on the go. I did a quick google search and found out that there already is a stream player for android out there, called AntPlayer.
I think it's available on the market, and if the source is open maybe you can take a look.
I'm going to look it up on the market and see if it plays di.fm streams
Droidlive?
Yeah, I found a few that can do it, but haven't found any open source options yet. I'll look into AntPlayer. I'm trying to create an app for our university's radio station.
Any updates? I'm looking to do the same.
Same problem here!

managing external playlists on the HD2 and the problems I'm having now

I've had a look at the posts already made on this topic - the most useful one I've found so far is TommyRose's post. (t=665484) (sorry not allowed to post links yet).
As I understand it we can't get at the native playlists that the manila player uses - they're somehow hidden away from us - not even in any file that I can find.
I also understand that it is supposed to be possible to sync external playlists directly from WMP. I didn't get very far with trying to do this, mainly because I don't want to use WMP.
I really wanted to use Winamp - it will happily sync to portable devices so I got it to do that (I made my HD2 look like a portable drive rather than using ActiveSync) - and it stuck an m3u playlist file on my device (in \Storage Card\Playlists [I set this up in Winamp preferences I think]) along with the music in the folder structure that I specified.
The playlist was in the wrong format - an m3u. But if you look inside this file it's easy enough to convert it to the asx format required by the Manilla player on the HD2 - which is definitely the player that I want to use!
The format inside the m3u looks like this:
Code:
#EXTM3U
\path_to_your_music_file\a_track.mp3
\path_to_your_music_file\another_track.mp3
But the format inside the asx file has to look like this:
Code:
<ASX>
<ENTRY><REF HREF="\Storage Card\path_to_your_music_file\a_track.mp3" /></ENTRY>
<ENTRY><REF HREF="\Storage Card\path_to_your_music_file\another_track.mp3" /></ENTRY>
</ASX>
Interesting point: the tags have to be CAPITALISED or the Manilla player won't show the track in playlist display.
So far so good - I can use my playlists from Winamp on my PC on my HD2 - after doing some text editing on it and renaming it to an asx (I made a perl script to do this automatically)
Code:
#!/usr/bin/perl
open FILE_A, "<", "$ARGV[0].m3u";
open FILE_B, ">", "$ARGV[0].asx";
print FILE_B "<ASX>\n";
<FILE_A>;
while(<FILE_A>)
{
my($line) = $_;
chomp($line);
print FILE_B "<ENTRY><REF HREF=\"\\Storage Card$line\" /></ENTRY>\n";
}
print FILE_B "</ASX>\n";
close FILE_A;
close FILE_B;
So now my external playlists show up with all their tracks in the manila player
The problems I'm having now:
1. If I use one of my asx playlists in the Manilla player and hit Menuroperties It shows the properties of the track I'm playing - but it's missing some tag info. If I play the track a different way (without using the asx playlist) the tags show up correctly.
2. This is the most annoying: If I play tracks using one of my asx playlists and then hit Menu:Add to Playlist it shows me all of my native manila made playlists that I can add this track to ... but when I hit one of those the whole thing crashes "A problem has occurred with manila.exe" sometimes it says services.exe too. This only happens with the asx playlists - I can happily Add to Playlist using a track from one of my native playlists - or a track I've played by navigating to it another way.
This feels like a bug in the manila player to me
I'd like to know if anyone else has experienced these problems - and if they know of any solutions or ROMS that solve them? I'd love to have the ability to create favourites playlists on my device as I'm playing the music I've synced into it from winamp using my external playlists.
My HD2 is using:
OS 5.2.21869 (21869.5.0.82)
Manila 2.5.19211619.0
ROM 1.66.405.2(76641) WWE
Hi, arctic giraffe, I tried your solution on my Touch HD with the same Manila version, 2.5.19211619.0, so I think it should work well as your HD2: I made an .asx playlist using syntax you suggested, but Audio manager doesn't recognize it. Otherwise, if I create a playlist without extension (like eldest versions of Manila), which syntax was simply
\path_to_your_music_file\a_track.mp3
\path_to_your_music_file\another_track.mp3
then it recognize playlist in the apposite tab, but I can only see its name, if I try to open it, it's empty. I think that all playlist informations are stored in the file AudioManager_Eng.vol, so I tried to open it with a text editor, but its content is inapprehensible! If you have any idea, please help me!! I think it's impossible that you can make playlist only with Audio Manager (which is long and not pratical)!

[Q] Hello, I have an issue with the media player on rotation

I have a media file playing in the oncreate, and everytime i switch over to landscape it replays the audio file, i cannot restrict it from turning to land scape because thats the purpose of the app, is there any way i can possible pause the player and start it up again once its on landscape?
i tried
if(alert.isPlaying() == true){
alert.stop;
}else{
alert.start;
}
Click to expand...
Click to collapse
I just typed this out in this post so i know i made an error, im still new to android programming.
Please and thank you,
Alexander Napoles
Take a look at this.
You could also save if it has already been played in a variable.
Or make an extra class, maybe as activity to play to play the audio file. Use an addiotinaly variable to procted the class from being created twice, because we only want to play it once.
This should keep running in the background and not start again when going landscape mode because it is not part of the activity that is getting recreated when you switch your gui to landscape.
Thank you "Clicks Thanks button" Im going to be testing this out tomorrow morning.

how do i launch music player with a particular song / album?

i thought it may be with an intent but can't find anything, nor can i find anything in the mediaplayer class, but what do i have to do to trigger the stock music player and do i have to pass in a filename as the param?
mhh, something like:
Code:
Uri data = Uri.parse("file://" + mf1.getFilename());
MediaPlayer mp = android.media.MediaPlayer.create(this, data);
mp.start();
will only trigger it as a background process, not switch to it. and an intent view seems to launch a mini player inside the app, so how do i switch to the music player?
http://forum.xda-developers.com/showpost.php?p=13036528&postcount=4
Note: TouchWiz has it's own DB for music for Samsung phones, so you know, we hate them (and the second method may/maynot work on TouchWiz phones).
thanks, i need to get my head around querying the content provider now!

[Q]How to rip streaming music radio app

I have an Online Radio App and would like to add some sort of recording feature on it. I have done quite a bit of research and found one solution and from what I understand maybe the only solution is to rip it byte by byte. I have also tried to use the built in android recording method but it only records from the mic and I do not know or cannot figure out how to record from an external source such as a url like http://92.68.34.221:7000. Currently I am using the default Android media player method to play the url and its working flawlessly problem is I would like to set up the recording feature as a service to where when a the button is clicked run the service start recording and when it is clicked again terminate the service and save the file in a folder called online radio. Button might end up being a ToggleButton. I would really appreciate it if anyone could help me out and steer me in the right direction. Thanks in Advance
Saving a stream to file is quite easy, but if you want to define the exact start and end point of saving/recording by a button click it gets difficult.
You'll have to change your implementation a lot. Your android mediaplayer class handles everything for you, it opens the stream, fills a buffer and starts playing when the buffer is full. The mediaplayer doesn't offer any access to the bytes that it received.
Next problem: If you click on the button to start recording, the bytes you are listening to, have been in the (internal) buffer for an unknown amount of time. So you can't just open another connection to the stream url to start saving the bytes.
I would try it this way:
Implement these three parts in three different threads.
1. Use android.media.MediaExtractor to open the stream and implement a ringbuffer to store the extracted bytes
2. Use android.media.MediaCodec to decode your stream to pcm.
3. And use android.media.AudioTrack to play the pcm stream
Choose the size of the ringbuffer as large as the buffer of the AudioTrack. (Size in seconds, not in bytes!)
When the user clicks on the record button, you can read the data out of the ringbuffer, (encode them back to mp3 or something else) and save them to a file.
Not very easy for a beginner, but its a way you can do it.

Categories

Resources