I want to play a streaming video in android from a website.
For example, I want to play the streaming video from this url: http://florotv.com/canal2.html
Using URL Helper, I have been able to capture the rtmp URL that it's
rtmp://198.144.153.139:443/kuyo<playpath>ver44?id=acf6f5271f8ce567ed6c8737ce85a044&pid=32342e3136362e37332e323139 <swfUrl>http://yukons.net/yplay2.swf <pageUrl>http://yukons.net/embed/37363635373233343334/eeff74c57593ca38defc902fa6d88005/600/400
Now that I have this URL, I wanna know if it's possible to play the video in android.
I have tried this but it doesn't work because I don't know how to set the swfUrl, pageUrl.....
private static final String MOVIE_URL="rtmp://198.144.153.139:443/kuyo";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(MOVIE_URL);
intent.setData(data);
startActivity(intent);
Thanks in advance....
Add below code into your Activity.java file.
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoPlayer);
try {
String link="http://videocloud/video.mp4";
VideoView videoView = (VideoView) findViewById(R.id.myVideoView);
final ProgressBar pbLoading = (ProgressBar) findViewById(R.id.pbVideoLoading);
pbLoading.setVisibility(View.VISIBLE);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
pbLoading.setVisibility(View.GONE);
}
});
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}
If you don't need MediaController set it to null videoView.setMediaController(null)
I don't think it's enough to just create an intent, you also have to create a context for the video to be played : Like a VideoView object.
The link below has a suggestion for this pattern :
http://androidcodeexamples.blogspot.sg/2011/08/how-to-play-mp4-video-in-android-using.html
Essentially a MediaController object is created with the VideoView object. Then the VideoView is used to start the operation once the URI is set.
Edit :
Probably the main problem though is that your URL contains POST parameters and isn't exactly a unique identifier of a resource (in this case a video file).
The 'swfUrl' and 'pageUrl' parameters are most likely unique to the server that's providing you the page.
You can use Vitamio library for android, where you can set the swfUrl and pageUrl.
Here is a tutorial for it.
Related
Scenario
I have an Android App that utilizes a master/details layout.
So When I click "Videos" in the left panel, it navigates to a new panel where the video name and link is downloaded. Upon then selecting a title, the left panel hides and the video begins to play.
Problem
I've use a videoview, and oddly, I cant get the video to play. I dont really get an error, However the screen remains black, and I believe i hear the sound from the first few second of the video followed by the image i uploaded and no image.
See Code
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_drone_life3, null);
vidView=(VideoView)view.findViewById(R.id.ivEvent);
context=this.getActivity();
return view;
}
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long id) {
if (new ConnectionDetector(context).isConnectingToInternet()) {
//get VidLink variable of item in this location and place in the var videoLink
videoLink = eventsDTOs.get(position).getVidLink();
try {
MediaController mediaController = new MediaController(getContext());
mediaController.setAnchorView(vidView);
Uri video = Uri.parse(videoLink);
vidView.setMediaController(mediaController);
vidView.setVideoURI(video);
vidView.start();
MainActivity.closeSlidingDrawer();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getContext(), "Error connecting", Toast.LENGTH_SHORT).show();
}
// new TaskGetEventImage().execute(eventsDTOs.get(position).getId());
} else {
Toast.makeText(context, context.getResources().getString(R.string.NETWORK_ERROR),Toast.LENGTH_LONG).show();
}
}
For playing video from URL
VideoView videoView=(VideoView) findViewById(R.id.myVideo);
videoView.setVideoURI(Uri.parse("http://website.com/somevideoname.mp4"));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
For playing video from SD card or internal storage
MediaController vidControl;
String sdPath;
VideoView videoView=(VideoView) findViewById(R.id.myVideo);
vidControl = new MediaController(this);
vidControl.setAnchorView(videoView);
videoView.setMediaController(vidControl);
videoView.setVideoPath(sdPath);
videoView.requestFocus();
videoView.start();
I will suggest to try to use above solution for playing video.
Solved this, apprantly the error was my server doing some encoding that the phone couldnt handle.
I'm using the library Vitamio to play rtsp live stream. I tried to run the demo videoview class play rtsp link as follows:
http://117.103.224.75:1935/live/definst/VTCHD3/VTCHD3_840x480_1200kbps.stream/playlist.m3u8
==> Result : it run but quality very bad, load videos very low and picture in video are not sharp and sound are not heard. I don't know what to do to make it run smooth and picture is sharp. Please help me this problem ! Thank very much !
this is my code :
private String path="http://117.103.224.75:1935/live/_definst_/VTCHD3/VTCHD3_840x480_1200kbps.stream/playlist.m3u8";
private ProgressDialog prodlg;
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
prodlg=new ProgressDialog(this);
prodlg.setIcon(R.drawable.ic_launcher);
prodlg.setMessage("wating...");
prodlg.show();
mVideoView = (VideoView) findViewById(R.id.surface_view);
if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(VideoViewDemo.this, "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
return;
} else {
/*
* Alternatively,for streaming media you can use
* mVideoView.setVideoURI(Uri.parse(URLstring));
*/
mVideoView.setVideoPath(path);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mVideoView.setBufferSize(2048);
mVideoView.requestFocus();
mVideoView.start();
mVideoView.setMediaController(new MediaController(this));
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
prodlg.dismiss();
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
}
}
I use android platforms 4.0 api 14 play demo :
this is my screen picture demo
If you want to use Vitamio library for displaying video etc, then first of all download Vitamio Library from here Free download Vitamio Library.
then include both "ZI" and "InitActivtiy" (which is inside the Vitamio lib) Library in your current project (right click project-->include library-->), then write this line of code
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
after Oncreate Method() like in my project.
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)) //it will check the include library of Vitamio
return;
after that put this line of code in Androidmanifest.xml file
<!-- (((((( Vitamio Library including in manifest file )))))) -->
<activity android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden"/>
Now its a time to display your video using VideoView etc.
I have a simple button, and I wish to play an URL video buy clicking on this button but without a videoView.
So if I click on the button , the phone will ask which internal player I'll choose to play the video.
Here I was using a videoView that was playing the video inside the window of my application but I want it outside :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
video = (VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
Uri chemin = Uri.parse("http://commonsware.com/misc/test2.3gp");
video.setVideoURI(chemin);
video.start();
Thank you,
so here's the code :
boutonVideo = (Button) findViewById(R.id.boutonVideo);
boutonVideo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent in;
if (v.getId() == R.id.boutonVideo) {
in = new Intent(Intent.ACTION_VIEW, Uri
.parse(urlBandeAnnonce));
startActivity(in);
}
}
});
But it return me an error when I decide to stop the video and return to my activity.
Here is the AndroidRunTime Error :
java.lang.RuntimeException: Unable to start activity
ComponentInfo{Activity}: java.lang.NullPointerException
09-30 15:20:16.449: E/AndroidRuntime(2301):
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
Solved
So I add finish(); and the error disappear.
Use an Intent with ACTION_VIEW along with the URI to the movie you want to play:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieUrl));
startActivity(intent);
where movieUrl is a string containing the path to the movie.
This may or may not work with internet streams. Haven't tried it with those personally.
Have you looked to Android Api examples
if you have installed the samples on your pc it is located at (for windows systems)
C:\Program Files\Android\android-sdk\samples\android-16\ApiDemos\src\com\example\android\apis\media
I'm a Flash developer by trade, have recently made the jump into Android as the company I work for are moving into apps. I've made a video gallery based on an XML feed, it all works fine until I have to play the movie itself, at which point I get:
Unable to play video. Invalid streaming data.
My gallery items fire up another activity with the .mp4 link as an extra:
public class Video_play extends Activity implements View.OnClickListener {
String vLink;
Uri vid;
VideoView vv;
MediaPlayer mp;
SurfaceHolder holder;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//Hide app title
Bundle extras = getIntent().getExtras();
if (extras != null) {
vLink = extras.getString("video");
vid = Uri.parse(vLink);
}
setContentView(R.layout.vidplay_layout);
vv = (VideoView)findViewById(R.id.vid_fscreen);
Log.i("Video link is: ",vid+"");
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(vv);
vv.setMediaController(mediaController);
vv.setVideoURI(vid);
vv.start();
}
public void onClick(View v) {
}
}
I've been looking all afternoon and I can't find any straightforward advice on what I'm doing wrong. Any help would be absolutely life-saving, thanks in advance.
What version of Android are you testing it on? HTTP progressive streaming for MP4 video was not fully supported until Android 2.2.
For streaming playback on earlier Android versions you can usually work around this by using post-encoding software like MP4Box to add "hint tracks" to the file:
MP4Box -hint <filename>
http://www.videohelp.com/tools/mp4box
I want to play video of mp4 format and size 4-5Mb from server in streaming mode.I am using sdk version 2.3,on emulator it
gives only sound but not any picture.
I also tested it on devices Samsung(android sdk ver 2.1) and LG optimus(android sdk ver 2.2)
and only get "cannot play video:sorry this video is not valid for streaming to this device" message.
I have searched on this but not getting any solution, if anybody have any solution please help me.Thanks in advance.
Here is my code:
public class ShowVideo extends Activity
{
private static ProgressDialog progressDialog;
public String video_url;
private MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoalbum);
progressDialog = ProgressDialog.show(ShowVideo.this, "", "Buffering video...", true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
video_url = "http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4";
try {
final VideoView videoView =(VideoView)findViewById(R.id.video_viewId);
mediaController = new MediaController(ShowVideo.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());
}
}
You may try these urls (ends with .3gp):
http://daily3gp.com/vids/747.3gp
http://daily3gp/www/vids/juggling_while_on_unicycle.3gp
instead of .mp4 urls:
video_url = "http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4";
On emulator it is difficult to get video played, because it needs really fast computer. Try this link for emulator. Maybe you can get some discrete video view.
http://commonsware.com/misc/test2.3gp
Also in your real devices this link should work if your implementation is proper.
I assume your video using following link
"http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4
is not proper for safe streaming.
You should hint that video or play other hinted videos. I couldn't find any other solution for playing unhinted videos yet.
This link may help.
getting PVMFErrContentInvalidForProgressivePlayback error while playing mp4 files on samsung devices