Android-Media Player - android

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

Related

Want to add thumbnail to videoview. in android studio

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

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

display time on android media controller

Am I missing something? Once I play a video using videoview, I cannot see the current time of the video on the media controller. (Running app on a ICS device, there is no time; however on a Honeycomb device there is time)
Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
// Use a media controller so that you can scroll the video contents
// and also to pause, start the video.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView
.setVideoURI(Uri
.parse("rtsp://v6.cache5.c.youtube.com/CiILENy73wIaGQmCZld_oqDeJhMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
videoView.start();
}
Actually I noticed the time is there but it's so dim and I cannot see it. Is there any way that I can change the theme of the media controller?
The answer is kind of general to all of the controllers such a mediacontroller, dialog, toast, etc.
you can use ContextThemeWrapper:
instead of:
MediaController mediaController = new MediaController(this);
you can use:
MediaController mediaController = new MediaController(new ContextThemeWrapper(this,R.style.CustomTheme));

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

not able to play video in the emulator

public class VideoViewActivity extends Activity {
private String vSource;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoviewacti);
VideoView vView = (VideoView)findViewById(R.id.videovw);
vView.requestFocus();
String LINK = ConstantData.urlVideo;
Log.i("path of video",""+LINK);
vView.setVideoURI(Uri.parse(LINK));
//vView.setVideoPath("sdcard/test30fps.mp4");
MediaController mediacontroller = new MediaController(this);
vView.setMediaController(mediacontroller);
vView.start();
}
}
here the video doesn't play in the emulator.It shows the error like "Can not play video"
video format is mp4 on the webservice.
when it opens the video file then the controls of the mediaplayer get disabled.

Categories

Resources