How to play server m3u file directly without download in android - android

In my application I want to play server m3u file directly with out downloading the file. For this i am using bellow code
String url = "http://........"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();`enter code here`
But did not work.
this is the server url file
http://stream.abacast.net/playlist/mwfmadison-wrisfmmp3-ibc3.m3u.
So can any one please how to do this

Related

Playing a music file while downloading it

I'm developing a music download App that basically does webscraping across differents torrent platforms and get the torrents. I want to play some music torrent files while I'm downloading them. I have a Service that basically takes care of doing all this. I set a buffer that waits until the torrent file Its at least 25% downloaded, then I use the MediaPlayer class to start playing the file. The music starts playing OK, but It stops after a while, as if It couldn't play more than that 25%. I tried using both the Android's MediaPlayer class and the FFmpegMediaPlayer library. I tried using several configs:
MediaPlayer mediaPlayer = new MediaPlayer();
FileInputStream fis = null;
try {
fis = new FileInputStream(mCurrentTrack);
mediaPlayer.setDataSource(fis.getFD());
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
});
mediaPlayer.prepareAsync();
} catch (Exception e) {
Log.w(APP_TAG, String.format("Something went wrong while trying to play the torrent stream: " + e.toString()));
}
mCurrentTrack is the path to the mp3 file that I downloaded into my Download folder in the external storage.
I tried using AudioManager.STREAM_MUSIC. I tried using the sync prepare() method and then calling the start() method. I triead opening the file with a new File(mCurrentTrack) before start playing It and setting It as readeable and writable. I tried many combinations, but always is the same, the music plays a few seconds and then stops. When I check the external storage, the file ends up being fully downloaded without trouble.
The library that I'm using to download the torrent files is this one TorrentStream-Android
Any tip or idea about how play this file while its being downloaded in the fly, would be appreciated.
As someone pointed out here. Using the ExoMedia player library solved the issue. Here's the snippet that I used to get it working:
compile 'com.devbrackets.android:exomedia:3.1.0'
final EMAudioPlayer mediaPlayer = new EMAudioPlayer (getApplicationContext());
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared() {
mediaPlayer.start();
}
});
mediaPlayer.setDataSource(getApplicationContext(), Uri.parse(mCurrentTrack));
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();

Media Player set path of another folder

I am making a simple app that plays an mp3 file. I use the code
mp = MediaPlayer.create(MainActivity.this, R.raw.mysong);
But this works only if my song is saved in the res\raw folder of my PC. Sooner or later I will run the app of my iphone (as soon as I buy one!). What happens if I must set the path to the one that the mobile is saved? Let's say my Downloads folder from my mobile phone.
You can do it by giving it it's absolute path from the ExternalStorage as follwoing
mp = MediaPlayer.create(MainActivity.this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/mysong.mp3"));
OR Use setDataSource() method:
String PATH_TO_FILE = "/sdcard/music.mp3";
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(PATH_TO_FILE);
mediaPlayer.prepare();
mediaPlayer.start()
String filePath = "somepath/somefile.mp3";
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare();

Dynamic Http Streaming in Android to play live Flash video

I am trying to connect my android application with FTP Server which is broadcasting multiple streams using Dynamic Http Streaming at different bit rates.Flash Messaging Server(FMS) is using H.264 codec to broadcast video in flv format.On client side(Android) I am getting f4m(manifest (xml) file)) having diffrent streams.
I am unable to use the f4m file to fetch video in android from FMS.
String url = "http://d2233avv69kunu.cloudfront.net/hds-live/livepkgr/_definst_/liveevent/livestream.f4m";
Uri uri = Uri.parse(url);
// videoView.setVideoURI(uri);
videoView.setVideoPath(str);
MediaController mc = new MediaController(this);
//VMRuntime.getRuntime().setMinimumHeapSize(40);
mc.setAnchorView(videoView);
videoView.setMediaController(mc);
System.out.println("Max Memory - "+java.lang.Runtime.getRuntime().maxMemory());
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
videoView.start();
}
});
In above code I am trying to run video in Video View component by passing link of f4m file.
Flash encoder convert video into 3 file formats as listed below
.f4m (manifest files) - Bootstrap Info,Metadata, Bitrate, Flash Access license Server location
.f4f (fragment files) - extends the F4V format,MP4 fragment std
.f4x (index files) - binary
Kindly provide solution to play video on different android devices via Http Streaming in android.
Thanks in advance.
1) You have left something out of your code. What is str that you are passing to setVideoPath? (this is somewhat irrelevant, though...)
2) The MediaPlayer (and thereby VideoView) cannot play Flash video at all. It's simply not supported. It definitely won't understand an XML file, either, so passing it the f4m file is pointless.

VideoView can play mp4 file in application data directory

While save mp4 file to /data/data/mypackage/files/my.mp4, then call VideoView's setVideoPath(); it can not work.
For the same file, if I save the file to /mnt/sdcard/my.mp4, then call the same VideoView's setVideoPath, it plays correctly.
Is there any way I can play mp4 file under /data/data/mypackage/files/?
The MP or VideoView uses a native player which cannot access non-worldreadable files.
So you have to options basically:
1) Make the created files world-readable
2) Open an input stream to the file in your program and just hand over the file descriptor to the media player:
FileInputStream fi = new FileInputStream(file);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fi.getFD());
pl.prepare();
pl.start();
Also look at this thread VideoView/MediaPlayer doesn't play video from internal storage And find a Custom VideoView class code from here also look at this SO question Can a videoview play a video stored on internal storage?

How to stream mp3 from shortened URL

I have an mp3 file in a shortened URL:
http://services.xyz.net/2_4/download?file=l9G0qe5b%2fiMDXhIGuvMhHg%3d&token=c371ae3c-ed65-4991-bbdc-bd2e5333116e
The file is not getting played if I use the shortened URL. I am getting IOExeception in MediaPlayer.prepare() but if I put the file in public server and try to play using the fully qualified URL it plays. But the Blackberry and the iPhone are able to play the same song using the same shortened URL. I have a requirement to use the shortened URL. How to stream mp3 file and play for this type of shortened URL? If I put that shortend url in device browser then the file is getting downloaded from that place. This url is not redirecting to any other url. Also I have tested the same code works for some other shortened URL from the same server.
if(player!= null){
player.stop();
player.reset();
player.release();
player = null;
}
String url ="http://services.xyz.net/2_4/download?file=l9G0qe5b%2fiMDXhIGuvMhHg%3d&token=c371ae3c-ed65-4991-bbdc-bd2e5333116e";//for this not working
/*
String url = = http://203.123.181.194/downloads/sunil/Try.mp3;//here its working
*/
System.out.println("....URL...."+url);
player = new MediaPlayer();
player.setDataSource(url);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepare();
player.start();

Categories

Resources