Want to add thumbnail to videoview. in android studio - android

Actually in this
1.I want to add Thumbnail to my videoview.
2. In this I have 3 videoviews and even I want to make videoview to full screen.
I tried seeing many youtube videos still that didn't helped me. I tried doing that still I didn't got the expected output. Can anyone please help me.
this is my bvideos.java code.
public class bvideos extends AppCompatActivity {
private VideoView videoView;
private MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bvideos);
Button photo = (Button) findViewById(R.id.bphoto);
photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent y = new Intent(bvideos.this, mainpage.class);
startActivity(y);
}
});
videoView = findViewById(R.id.video_view1);
Uri videoUri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.bvideo1);
videoView.setVideoURI(videoUri);
mediaController = new FullScreenMediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
/*videoView.start();*/
videoView = findViewById(R.id.video_view2);
Uri videoUri1 = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.bvideo2);
videoView.setVideoURI(videoUri1);
mediaController = new FullScreenMediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
/*videoView.start();*/
videoView = findViewById(R.id.video_view3);
Uri videoUri2 = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.bvideo3);
videoView.setVideoURI(videoUri2);
mediaController = new FullScreenMediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
}
}

Ref: https://stackoverflow.com/a/32517167/13533028
https://stackoverflow.com/a/5950165/13533028
1st Method
Bitmap bMap = ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(), MediaStore.Video.Thumbnails.MICRO_KIND);
The Thumbnails part decides the type of thumbnail it will be.(big or small)
2nd Method
https://github.com/sushinpv/SuziVideoThumbnailLoader
This is a library which will make it easier for you to implement
3rd Method
Using Glide
Glide.with(context)
.load(uri)
.placeholder(R.drawable.ic_video_place_holder)
.into(imageView);

Related

How to play YouTube video in Android player?

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

Videoview is not playing .3gp file

I am trying to play .3gp file from a live RTSP. following is my code,
public class MainActivity extends Activity
{
// String path = "rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp";
String path = "rtsp://217.146.95.166:554/live/ch12zqcif.3gp";
VideoView videoView = null;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView =(VideoView)findViewById(R.id.videoView);
videoView.setVideoURI(Uri.parse(path));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
}
#Override
public void onBackPressed()
{
super.onBackPressed();
if ( videoView != null )
{
videoView.pause();
videoView = null;
}
}
}
I have given INTERNET Permission in my AnroidManifest.xml file.
When I load the first path variable with Youtube one, it is working file and loading the video but the second RTSP url is not working.
What could be the problem for this..?
May be the problem is with you is your URL please verify the rtsp url. Here is the example for how to playvideo with the videoview.
Cheers

Streaming video with videoview

My code below to streaming video:
VideoView vv = (VideoView)this.findViewById(R.id.screen_video);
Uri uri = Uri.parse(URL);
vv.setVideoURI(uri);
vv.start();
It works.
But if the URL video's format not support by android phone or pad.
It show a dialog, and not show the screen.
But it still streaming with black screen.
I want to get the error message, and access as an exception.
But I don't know how to get it?
Another problem is that the streaming may crash cause by low speed wifi.
How to check it to wait while low speed wifi?
try this code,it work,
public class PlayVideo extends Activity
{
private String videoPath ="url";
private static ProgressDialog progressDialog;
String videourl;
VideoView videoView ;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.play_video);
videoView = (VideoView) findViewById(R.id.videoView);
progressDialog = ProgressDialog.show(PlayVideo.this, "", "Buffering video...", true);
progressDialog.setCancelable(true);
PlayVideo();
}
private void PlayVideo()
{
try
{
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mediaController = new MediaController(PlayVideo.this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(videoPath );
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.requestFocus();
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.toString());
finish();
}
}
}
It depends on which Android Version you are developing your application on. There are certain devices which do not support running .mp4 file. Go through Android Media support for more information. Check if you can play any .3gp files or not.
You shouldn't play the video instantly. Add OnPrepared listener to the video view and start the video playing after it. With MediaPlayer you could keep track of the buffering state and stop the video for a while when its not yet downloaded. Please have a look at this guide.
Try Intent to avoid that error. or put try catch in your block.
VideoView can only Stream 3gp videos but i recommend this code to stream your video
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.main);
String videourl = "http://something.com/blah.mp4";
Uri uri = Uri.parse(videourl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
}
Or Click here to watch Android Video Streaming Tutorial.

How to stream video in Android Emulator?

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

Android-Media Player

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();

Categories

Resources