Live audio streaming with Android 2.x - android

I need to play a live stream on devices with 2.x and greater versions. This states that it's impossible to play live streams on devices with Android 2.x.
What're my options here ? Especially I'm interested in streaming audio - what format should i pick and in conjunction with which protocol ?
P.S. I've tried Vitamio - don't want to make customers download third party libraries.
UPD
How come I can play this stream "http://188.138.112.71:9018/" ?

try this example for RTSP streaming (the url should support RTSP) for video change the code to support just audio
public class MultimediaActivity extends Activity {
private static final String RTSP = "rtsp://url here";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.multimedia);
//***VideoView to video element inside Multimedia.xml file
VideoView videoView = (VideoView) findViewById(R.id.video);
Log.v("Video", "***Video to Play:: " + RTSP);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
Uri video = Uri.parse(RTSP);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
}
}
EDIT:
Live Audio streaming using MediaPlayer in Android
Live Audio streaming in android, from 1.6 sdk onwards is become so easy. In setDataSource() API directly pass the url and audio will play without any issues.
The complete code snippet is,
public class AudioStream extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = "http://www.songblasts.com/songs/hindi/t/three-idiots/01-Aal_Izz_Well-(SongsBlasts.Com).mp3";
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(url);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.prepare();
mp.start();
} catch (Exception e) {
Log.i("Exception", "Exception in streaming mediaplayer e = " + e);
}
}
}

You can use RTSP protocol which is supported by Android native media player.
player = new MediaPlayer();
player.reset();
player.setDataSource(intent.getStringExtra("Path"));
player.prepare();
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
player.start();
}
});
Where path would be your rtsp audio streaming url.

Related

No response on full screen activity (different android version?)

Here is my code on full screen video.
It work just fine in emulator but not in real android phone.
public void videoClick(View view){
Intent mIntent = new Intent(getBaseContext(),VideoFullscreenActivity.class);
videoUri = Uri.parse("android.resource://tk.myessentialoils.ideasapp/raw/"+ contentStringList[count][2]);
mIntent.putExtra("videoUri",videoUri);
startActivity(mIntent);
}
My thinking is that the Uri problem.
Xiaomi android have different uri than other.
Some Huawei phone also not functioning well.
So is there any alternative to get the file instead?
Perhaps a work around that will work on all version of android.
Edit 1
as per Vivek Mishra suggestions,
tried the below
Intent mIntent = new Intent(getBaseContext(),VideoFullscreenActivity.class);
String path = "file:///android_asset/"+ contentStringList[count][2];
videoUri = Uri.parse(path);
mIntent.putExtra("videoUri",videoUri);
startActivity(mIntent);
However i got this error >> Can't play this video
as per How to load videos from assets folder? (to play them with VideoView) asset folder cannot play video
Edit 2
same question as Nullpointerexception, i cant get the Media player to work with my code.
Uri videoUri = getIntent().getParcelableExtra("videoUri");
VideoView videoView=findViewById(R.id.myvideoview);
videoView.setVideoURI(videoUri);
//videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.full));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
how do i implement the below code in my code above.
AssetFileDescriptor afd;
try {
afd = getAssets().openFd("v.mp4");
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),
afd.getLength());
player.prepareAsync();
player.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
} catch (Exception e) { e.printStackTrace();}

Audio Stream Not playing in smart phone

Iam trying to built an android application for playing online radio. The code is working in emulator properly. but when installed in phone it does not works.
MediaPlayer mediaPlayer = new MediaPlayer();
String url = "http://5293.live.streamtheworld.com:3690/JACK2_LOWAAC_SC";
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();
Is there any problem in the link format? I tried to play same link in html5 its working fine on desktop but the same website when opened in phone the link is not working. Also are there any issues or any components in html5 which do not work in smart phones bu work on Desktop ?
I need to play the live stream not the static file like mp3. You can take some URL form www.listenlive.eu/uk.html and try to play.The URL in my code is form this site only. download the VLC file and open it with any text editor and you will get url.
use mediaPlayer.prepareAsync(); instead of mediaPlayer.prepare(); since your are streaming from web and also add permission for internet
<uses-permission android:name="android.permission.INTERNET"/>
Also
String url = "http://5293.live.streamtheworld.com:3690/JACK2_LOWAAC_SC";
doesn't work for me instead i use
final String url = "http://vprmix.streamguys.net/vprmix64.mp3";
private boolean isPLAYING = false;
public void streamAudio(String url) {
if (!isPLAYING) {
isPLAYING = true;
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepareAsync();
mediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
Log.e("mediaPlayer", "prepare() failed");
}
} else {
isPLAYING = false;
stopPlaying();
}
}
private void stopPlaying() {
mediaPlayer.release();
mediaPlayer = null;
}

Android VideoView won't Play

So I'm trying to play a basic avi video in android, it seems to run fine on Windows Media Player, VLC, etc. so it doesn't look like it's requiring any complicated codecs. I have a video view in my app and that's it, and I have my video in my resources directory under:
res/raw/my_video.avi
This is the code I'm using to load my video:
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.start();
And it does not work. I get a popup saying "Can't play this video" along with a logcat message:
03-10 01:42:12.102: E/(185): Failed to open file 'android.resource://com.securespaces.android.bootstrap/2130968576'. (No such file or directory)
03-10 01:42:12.102: E/MediaPlayer(9737): error (1, -2147483648)
03-10 01:42:12.142: E/MediaPlayer(9737): Error (1,-2147483648)
I'm running this on a Nexus 5 running 4.4.2 stock by the way. I'm following instructions that I found in other stack over flow questions here: How to play videos in android from assets folder or raw folder? with some minor tweaks so that I am using a VideoView that I grab from a layout file.
I'm really stumped as to why this isn't working. I've browsed through a few questions on this subject, but this feels like something that should be a duplicate. I'm running this on a Nexus 5 running 4.4.2 stock by the way.
To clarify the question, I'm wondering what I am doing wrong, or is there an alternative for just playing a simple AVI video?
Write your package name statically and check whether video plays or not.
Try out as below:
VideoView videoView = (VideoView) findViewById(R.id.videoView1);
Uri video = Uri.parse("android.resource://com.securespaces.android.bootstrap/" + R.raw.my_video);
videoView.setVideoURI(video);
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
Implement this :
public static void getVideoFromRaw(String rawPath) {
try {
// Start the MediaController
MediaController mediacontroller = new MediaController(mContext);
mediacontroller.setAnchorView(mVideoview);
// Get the URL from String VideoURL
Uri mVideo = Uri.parse(rawPath);
mVideoview.setMediaController(mediacontroller);
mVideoview.setVideoURI(mVideo);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
mVideoview.requestFocus();
mVideoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
mVideoview.start();
}
});
mVideoview.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
}
});
}
Thanks

how to play and upload RTSP protocol through Live Video Stream on Android

Hello i have one rtsp live video url, I have't know how to play this live stream live Video url.
i am working on android sample application. Please share your guide with me.
Following code using to play live streaming url.
Don't have any idea, how to get live video streaming. Please suggest me any idea to send to live video stream to server.
below are my sample code.
public class MultimediaActivity extends Activity {
private static final String rtspURL = "rtsp://URL_IP:PORT+video+FileName";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.video);
Log.v("Video", "***Video to Play:: " + RTSP);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
Uri video = Uri.parse(rtspURL);
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
}
}
please suggest me, What should i do..?
Thank you..
Use this code for playing on player
Intent i1 = new Intent (Intent.ACTION_VIEW ,Uri.parse(rtspURL));
startActivity(i1);
and use this code for videoview
VideoView v1 = (VideoView)findViewById(R.id.videoView1);
v1.setVideoPath(rtspURL); //your rtspurl
v1.start()
this work for me ...

How to assign utube video url to android media player

I want that when i will pass the utube url to media player it will automatically load the video and play in it.
Example: http://www.youtube.com/watch?v=WAG8e_53le4
This type of url i want to play in android media player
If you want to play YouTube video in VideoView, you need rtsp url from youtube.
You can get the rtsp from Youtube Gdata feed. Although I find it quite strange that sometime the rtsp isn't available in the feed.
This works for me. It starts when the activity is created.
progressDialog = ProgressDialog.show(StevenBActivity.this, "", "Buffering video...", true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//video "DON'T DO IT" 1,315 views
video_url = "rtsp://v2.cache4.c.youtube.com/CjgLENy73wIaLwlPMIWk2hSzNRMYJCAkFEIJbXYtZ29vZ2xlSARSB3Jlc3VsdHNg6KnB9MbH8sVODA==/0/0/0/video.3gp";
//http://www.youtube.com/watch?v=NJNzBQvJpUI&list=UUy_BjNhdQh9-bfRuzuk53pg&index=9&feature=plcp
try {
final VideoView videoView =(VideoView)findViewById(R.id.videoView1);
mediaController = new MediaController(StevenBActivity.this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse(video_url);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.getMessage());
}
}

Categories

Resources