How to play aac audio file?

All your problems with Audio, Video and Images.

How to play aac audio file?

Postby yangwei0915 » Wed Dec 09, 2009 2:29 am

Hi,

I cannot play aac audio file, please help.



I download aac media file, put this file to sdcard named testaac.aac.

The blue font is my code:

MediaPlayer mMediaPlayer01 = new MediaPlayer();

mMediaPlayer01.setAudioStreamType(AudioManager.STREAM_MUSIC);

mMediaPlayer01.setDataSource(“/sdcard/testaac.aac”);

mMediaPlayer01.prepare();

Log.i(TAG, "Duration: " + mMediaPlayer01.getDuration());

mMediaPlayer01.start();



Run this code, there is no voice, but logcat display following message:

11-28 06:46:06.296: ERROR/PlayerDriver(554): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported

11-28 06:46:06.296: ERROR/MediaPlayer(734): error (1, -4)

11-28 06:46:06.355: ERROR/PlayMp3Stream(734): Prepare failed.: status=0x1

11-28 06:46:06.355: ERROR/PlayMp3Stream(734): java.io.IOException: Prepare failed.: status=0x1

11-28 06:46:06.355: ERROR/PlayMp3Stream(734): at android.media.MediaPlayer.prepare(Native Method)



What should I do?
yangwei0915
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Dec 09, 2009 2:20 am

Top

File path

Postby satishkumar_lskin » Wed Dec 09, 2009 8:08 am

Hi,
the path to the file should be "file:///sdcard/testaac.aac".

Thanks
Satish
satishkumar_lskin
Developer
Developer
 
Posts: 32
Joined: Mon Oct 20, 2008 8:15 am
Location: Coimbatore , TamilNadu, India

Re: How to play aac audio file?

Postby sakshidp » Fri Jun 11, 2010 6:47 pm

Hi:
I am trying to build internet radio application for fixed channel or link.

http://38.101.195.6/tori/listen_EST.m3u

here is my code.

private void playAudio()
{
final String path = "http://www.teluguoneradio.com/telugu-radioEst.html";

// Create a new media player and set the listeners

mp = new MediaPlayer();

mp.setOnErrorListener(this);
mp.setOnBufferingUpdateListener(this);
mp.setOnCompletionListener(this);
mp.setOnPreparedListener(this);
mp.setAudioStreamType(2);

// Set the data source in another thread
// which actually downloads the mp3 or videos
// to a temporary location
Runnable r = new Runnable() {
public void run()
{
try{
setDataSource("http://38.101.195.6/tori/listen_EST.m3u");
}
catch(Exception ex){Log.e(TAG, ex.getMessage());
}
try {
mp.prepare();
//Log.v(TAG, "Duration: ===>" + mp.getDuration());
mp.start();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Log.v(TAG, "Duration: ===>" + mp.getDuration());
// mp.start();
}
};

new Thread(r).start();
//} catch (Exception e) {
// Log.e(TAG, "error: " + e.getMessage(), e);
if (mp != null) {
mp.stop();
mp.release();
}
//}
}

/**
* If the user has specified a local url, then we download the
* url stream to a temporary location and then call the setDataSource
* for that local file
*
* @param path
* @throws IOException
*/
private void setDataSource(String path) throws IOException {
path="http://38.101.195.6/tori/listen_EST.m3u";
if (!URLUtil.isNetworkUrl(path)) {
mp.setDataSource("http://38.101.195.6/tori/listen_EST.m3u");
}
else {
URL url = new URL("http://38.101.195.6/tori/listen_EST.m3u");
URLConnection cn = url.openConnection();
cn.connect();
InputStream stream = cn.getInputStream();
if (stream == null)
throw new RuntimeException("stream is null");
File temp = File.createTempFile("mediaplayertmp", "dat");
String tempPath = temp.getAbsolutePath();
FileOutputStream out = new FileOutputStream(temp);
byte buf[] = new byte[128];
do {
int numread = stream.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
} while (true);
mp.setDataSource(tempPath);
try {
stream.close();
}
catch (IOException ex) {
Log.e(TAG, "error: " + ex.getMessage(), ex);
}
}
}

I don't know whether I have to parse the M3u link toString using URI .
Please give me suggestions.
What is wrong with this ?
I read at many blogs that internet radio app developer are using shoutcast or icecast ports to stream the data online.
Expanding Learning ability
sakshidp
Freshman
Freshman
 
Posts: 6
Joined: Wed Mar 31, 2010 4:27 pm
Location: albany,US

Re: How to play aac audio file?

Postby fbarnard » Tue Jun 15, 2010 2:38 pm

HI

As far as i know android does not support m3u(Its a playlist format not a audio/video format).

Here is the formats its support
http://developer.android.com/guide/appendix/media-formats.html

If you want you can take the m3u file appart and then just get the url to the actual audio/video and play them with media player

http://en.wikipedia.org/wiki/M3U
fbarnard
Developer
Developer
 
Posts: 44
Joined: Tue Jun 15, 2010 12:31 pm

Re: How to play aac audio file?

Postby sakshidp » Tue Jun 15, 2010 3:00 pm

Thanks for the reply .
I am really stuck up with this problem.
I found Mediascanner.java which processes M3Uplaylists.
http://www.netmite.com/android/mydroid/ ... anner.java
Haven't used yet .If anybody is working on it please reply.
Expanding Learning ability
sakshidp
Freshman
Freshman
 
Posts: 6
Joined: Wed Mar 31, 2010 4:27 pm
Location: albany,US

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 17 guests