Everyone. I would like to videoview displays the video in full screen, I've tried using some commands, but they didn't work out. I need some help. I put below my code.
The video continues showing about 1/3 of screen! I'm a newbie!!!
Intro.JAVA
public class Intro extends Activity {
public void onCreate(Bundle b) {
super.onCreate(b);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.intro);
VideoView vid = (VideoView) findViewById(R.id.videoView1);
String uriPath = "android.resource://com.english/raw/videoenglish";
Uri uri = Uri.parse(uriPath);
vid.setVideoURI(uri);
vid.start();
vid.requestFocus();
vid.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
Intent main = new Intent(Intro.this, IntentsDemoActivity.class);
Intro.this.startActivity(main);
Intro.this.finish();
}
});
}
}
INTRO.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<VideoView
android:id="#+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
</LinearLayout>
Usually, the actual video will not fill the screen a lot of the time, because the aspect ratio of the video does not match the aspect ratio of the screen itself.
I suspect that the VideoView itself is filling up the whole screen. Try with a different device or the emulator.
Here are some other questions for reference either way:
Reference 1
Reference 2
Related
I am playing video in Android Video view.Issue is video is not resizing as per device ratio. On big devices it stretched or in small device it is skeqzes. Is there any way to maintain ratio and fill full width like center crop.
I have checked following answers:
Resize video to fit the VideoView
Android VideoView orientation change with buffered video
But nothing works.
My code :
mBinding.videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
#Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
mBinding.placeholder.setVisibility(View.GONE);
return true;
}
return false;
}
});
mp.setLooping(true);
}
});
XML :
<VideoView
android:id="#+id/videoView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
Wrap the whole xml layout into a RelativeLayout. then modify your VideoView tag as following-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView android:id="#+id/videoView"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
</RelativeLayout>
I want to resize my video and show it in the video view and maintain the quality of the video also, my main focus is that the video quality should not be harmed and it should be shown in the video view
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView= (VideoView)findViewById(R.id.videoViewR);
Video v=new Video();
MediaController mc= new MediaController(this);
mc.setAnchorView(videoView);
Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/eveq.3gp");
videoView.setMediaController(mc);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
and my xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<VideoView
android:id="#+id/videoViewR"
android:layout_width="wrap_content"
android:layout_height="480dp"
android:layout_centerVertical="true" >
</VideoView>
</RelativeLayout>
If I understand your question then you don't have to do any special programming to resize the video to your VideoView. Let the MediaController and VideoView do all the scaling work for you.
First, your VideoView seems unusual (Why is height spec'd as 480 when the relative layout is only 270?). I'd suggest changing your VideoView to something like this:
<VideoView
android:id="#+id/videoViewR"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:adjustViewBounds="true"
android:scaleType="center" />
This will make the VideoView expand to the space available in the RelativeLayout and will adjust the bounds automatically.
Then the RelativeLayout should be as large as possible or the size you want (480x270 ?). To fill the space try
android:layout_width="match_parent"
android:layout_height="match_parent"
This will grow the layout to fill the space. Your video will then be scaled to fit these boundaries.
Since 24 hours I'm trying to set the Anchor view of my MediaControler without success.
My VideoView is embedded in a bigger application but even with a very simple testing app I don't understand the problem.
Here is the code of the onCreate of my testing activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final VideoView vv = (VideoView) findViewById(R.id.videoView1);
vv.setVideoURI(Uri.parse("http://192.168.30.188/test.mp4"));
final MediaController mediaController = new MediaController(ll.getContext());
vv.setMediaController(mediaController);
vv.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mediaController.setAnchorView(vv);
}
});
vv.requestFocus();
}
And here is my simple layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<FrameLayout
android:id="#+id/layout1"
android:layout_width="218dp"
android:layout_height="162dp"
android:background="#android:color/holo_purple">
<VideoView
android:id="#+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</RelativeLayout>
It seems that the media controller appears aligned with the bottom of my video view, but ever horitzontally centered !!!
I had a look at a lot of stack overflow "solutions" (more or less good) or other site samples and I can't understand ...
Can anybody help me please ?
I am trying to create a view that has a video playing and two ImageButtons all on the same screen. I am using VideoView to contain my video and ImageButtons for both of my buttons. Both display correctly when I test each feature independently, but they will not display together at the same time when I try to show both on the same screen! I have tried a number of layouts (frame, linear, relative), constraining the VideoView to a smaller layout_width & layout_height, and have tried weights in the xml file, but nothing seems to be working. Displaying this seems too straightforward to require a custom View, but I will do it if I have to.
Here are my questions: do you know how to make imageButtons and VideoView display on the same screen?
Can you use Android views like VideoView and ImageButton when you create a custom view? Or can you just draw 2D things on canvases in custom views?
Here is my code as reference: XML
<LinearLayout
android:id="#+id/videopart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="1">
<VideoView
android:id="#+id/videoplayer"
android:layout_width="395dp"
android:layout_height="111dp" >
</VideoView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<ImageButton
android:contentDescription="#string/top"
android:id="#+id/topbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:src="#drawable/yesbutton"
android:background="#null"/>
<ImageButton
android:contentDescription="#string/bottom"
android:id="#+id/bottombutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:src="#drawable/nobutton"
android:background="#null">
</ImageButton>
</LinearLayout>
And activity:
public class iplayer extends Activity {
VideoView videoHolder;
MediaPlayer mp;
ImageButton top, bottom;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoHolder = new VideoView(this);
//if you want the controls to appear
videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.interactivevid);
videoHolder.setVideoURI(video);
// video finish listener:
videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
// The video has finished, return from this activity
finish(); //close activity
}
});
videoHolder.requestFocus();
/*
videoHolder.requestLayout();
videoHolder.invalidate();
videoHolder.getLayoutParams().width = 20;//480;
*/
//start video
drawButtons();
//videoHolder.setPadding(BIND_NOT_FOREGROUND, BIND_NOT_FOREGROUND, BIND_NOT_FOREGROUND, BIND_NOT_FOREGROUND);
videoHolder.setPadding(5, 0, 5, 200);
setContentView(videoHolder); // used to actually put in video. when removed, shows buttons
videoHolder.start();
}
private void drawButtons(){
//make buttons invisible
top = (ImageButton)findViewById(R.id.topbutton);
top.setImageResource(R.drawable.yesbutton);
top.setVisibility(View.VISIBLE);
bottom = (ImageButton)findViewById(R.id.bottombutton);
bottom.setImageResource(R.drawable.nobutton);
bottom.setVisibility(View.VISIBLE);
}
}
I'm not by a computer where I can test this now but what you may want to try is an absolute layout.
You should be able to position the buttons on top of the video with it here is an example
http://www.tutorialforandroid.com/2009/01/absolutelayout-in-android-xml.html
You may also want to try putting the buttons and the VideoView in the same layout
I am trying to play a video through my application.
public class VideoScreen extends Activity {
public MediaPlayer videoMediaPlayer = new MediaPlayer();
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoscreen);
SurfaceView demoVideo = (SurfaceView) findViewById(R.id.demoVideo);
SurfaceHolder videoHolder = demoVideo.getHolder();
videoMediaPlayer = MediaPlayer.create(this, R.raw.help);
videoMediaPlayer.setDisplay(videoHolder);
videoMediaPlayer.setLooping(false);
videoMediaPlayer.setScreenOnWhilePlaying(true);
videoMediaPlayer.start();
}
}
XML File:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<SurfaceView android:id="#+id/demoVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></SurfaceView>
</FrameLayout>
I can hear only sound, but no video.
But, when I try to play this video separately through file manager. It is playing perfectly. Where I am wrong?
Please help.
I managed to play the video on my phone as well as simulator using VideoView
The changes done were:
Java File:
public class VideoScreen extends Activity {
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoscreen);
Uri raw_uri=Uri.parse("android.resource://com.binary/"+R.raw.myvideo);
VideoView videoView=(VideoView)findViewById(R.id.demoVideo);
videoView.setVideoURI(raw_uri);
videoView.setMediaController(new MediaController(this));
videoView.setOnCompletionListener(videoOverListener);
videoView.start();
videoView.requestFocus();
}
}
XML File:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<VideoView android:id="#+id/demoVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</VideoView>
</FrameLayout>
Hope this helps.