I am newbie in Android, and I tried a lot with my code to stream video in emulator, but I am getting exception "Sorry The application Hellovideodemo(...) has stopped unexpectly.
Here is the code:
public class HelloVideoDemo extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri
.parse("http://dev2010.excoflare.com/zencart/abhishek/BlackBerry_Social_Meeting/av/testing.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
Any help will really be appreciated. Thanks.
Have you declared the Internet permission as a child of the Android Manifest?
<uses-permission android:name="android.permission.INTERNET" />
setcontentview that function should have r.id.videoview not main try i guess it should work
Related
I want to play YouTube videos on Android without using YouTube app. It should play with Android player. We have tried using YouTube app, but we need to play YouTube videos directly with Android player, not using YouTube application.
Is it possible? If it is, how to do it?
try this.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse("your url in rtsp format");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
Its simple just create video view then add a new media controller to it, set the video URL in the video view and start the video it will work.
Add the below Code into your MainActivity.java file.
#Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.videodisplay);
String link="http://www.youtube.com/watch?v=JSnB06um5r4";
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}
You better try it on offline file to make sure that the video viewer is working fine (the video is compatible with device) then play it online
I'm trying to play video from youtube using this code but I get this error from my log cat:
06-28 16:23:09.794: E/MediaPlayer(621): error (1, -2147483648)
Here is my code:
public class PromoActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(com.frux.kfcmobile.R.layout.promo);
VideoView videoView = (VideoView)this.findViewById(com.frux.kfcmobile.R.id.videoView);
String path = "rtsp://v4.cache5.c.youtube.com/CjYLENy73wIaLQmofK96HM6gyhMYDSANFEIJbXYtZ29vZ2xlSARSBWluZGV4YJWAl-O04anmTww=/0/0/0/video.3gp";
Uri vid = Uri.parse(path);
videoView.setVideoURI(vid);
videoView.setMediaController(new MediaController(this));
videoView.start();
videoView.requestFocus();
}
}
Can anyone help me?
Try this code
video.setVideoURI(Uri
.parse("rtsp://v6.cache7.c.youtube.com/CiILENy73wIaGQk-fYZWNAPDsxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
mMediaController = new MediaController(this);
mMediaController.setMediaPlayer(video);
video.start();
And you try to run in Device.. Because in emulator only some videos will get played.
I am currently playing a video in andriod from the url http://daily3gp.com/vids/747.3gp
its working successfully.
But here i need to play that url through server, please let me know how to play.
Find the code below:
CODE
public class Activity3 extends Activity {
private VideoView videoView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main2);
videoView = (VideoView)this.findViewById(R.id.videoView_surface_1);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("http://daily3gp.com/vids/747.3gp"));
videoView.requestFocus();}}
Thanks for your Time!!
You have to call videoview.start() after this call only videoview will start playing video.
I wrote code for play video from URL. But I am getting UNABLE TO PLAY VIDEO message.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView);
mc.setMediaPlayer(videoView);
Uri video = Uri.parse("http://www.youtube.com/watch?v=qvtCk1wZ7LM&feature=player_detailpage");
videoView.setMediaController(mc);
videoView.setVideoURI(video);
videoView.start();
}
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/video"></VideoView>
You could simple fire an Intent to play the video by another app.
Here, Youtube app will detect a Youtube Video, and will prompt the dialog to play the video on your behalf.
String url = "http://www.youtube.com/watch?v=qvtCk1wZ7LM";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
But if you really want to integrate a video player inside your app, I strongly recommand you to take a look at the Youtube API.
Its simple just create video view then add a new media controller to it, set the video URL in the video view and start the video it will work.
Add the below Code into your MainActivity.java file.
#Override
protected void onCreate(Bundle savedInstanceState)
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.videodisplay);
String link="http://s1133.photobucket.com/albums/m590/Anniebabycupcakez/?action=view& current=1376992942447_242.mp4";
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(link);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(this, "Error connecting", Toast.LENGTH_SHORT).show();
}
}
You better try it on offline file to make sure that the video viewer is working fine (the video is compatible with the device) then play it from YouTube online.
Here is a simple and easy way to play the video.
xml file...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="2px" android:paddingRight="2px"
android:paddingTop="2px" android:paddingBottom="2px"
android:layout_width="fill_parent" android:orientation="vertical">
<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent" android:id="#+id/VideoView"></VideoView>
</LinearLayout>
java file.....
public class VideoPlayerController extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse("mp4 video link");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
some file format like youtube video file format cant open in video view.
videoview only support system file format can opend it like mp4 . 3gp . other...
for open fly video format you must use surfeview and create class that can handl this video type
and for get video from link use inputstream (dont use string)
other easy way to show youtube video is just use Intent.View,url(your video uri)
https://developer.android.com/guide/appendix/media-formats.html
Use Exo-Player , it is better choice to play videos and having lot of functionallity --Follow Exo Player Docs
I am new to android. I am trying to play a video from sdcard.
this is the sample code I have used:
public class videoa extends Activity {
/** Called when the activity is first created. */
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
// (1) Web
//videoView.setVideoURI(Uri.parse(
//"http://www.bogotobogo.com/Video/sample.3gp"));
//"http://www.bogotobogo.com/Video/sample.mp4"));
//"http://www.bogotobogo.com/Video/sample.mov"));
/* (2) SD card */
//videoView.setVideoPath("/sdcard/sample.3gp");
videoView.setVideoPath("/sdcard/robot.avi");
//videoView.setVideoPath("/sdcard/sample.mov");
// videoView.setVideoURI(Uri.parse(
//"file:///sdcard/sample.mov"));
videoView.requestFocus();
videoView.start();
}
}
I have launched manually And set the target as -sdcard C:/android-sdk-windows/tools/sdcard.img.
When i have launched the emulator it shows Video Cannot be Displayed.
Please help me out.
You try interchanging the 2 lines
final String MEDIA_PATH = new String("/sdcard/robot.avi");
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setVideoPath(MEDIA_PATH);
videoView.setMediaController(mc);
videoView.requestFocus();
videoView.start();