Android : Positionning the MediaController with setAnchorView - android

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 ?

Related

My Live vlc video stream works on the emulator but not on a real device

Hi I'm new to Android studio, I'm having an issue where I'm trying to play a vlc live steam on my phone but I get a message after a few seconds saying "video cannot be played". The strange thing is that video live stream will play on the emulator in android studio. I will add my code below. I have added internet permissions to the manifest also. If anyone could help it would be great, thanks in advance
//XML Code
<LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pkinsellaweb.BabyMate.VideoScreen"
>
<VideoView
android:id="#+id/videoView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
//Java Code
public class VideoScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_screen);
VideoView video = (VideoView) findViewById(R.id.videoView);
String vidAdd = "http://192.168.43.66:8160";
Uri videoPath = Uri.parse(vidAdd);
video.setVideoURI(videoPath);
MediaController mediaController = new
MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);
video.start();
}
}

How to resize the frames of video and show it in a fixed size video view in android

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.

Videoview android crash

I'm currently developing android app using eclipse. But, the app crash when after I put videoView. I put onCompletionListener so if the video end it automaticaly jump to main activity. Here it is the my videoview code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_video);
playVideo();
}
public void playVideo(){
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
setContentView(myVideoView);
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.endingvid);
myVideoView.setVideoURI(video);
myVideoView.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
jumpMain();
}
});
myVideoView.start();
}
And here it is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center"
android:background="#drawable/black"
>
<VideoView
android:id="#+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Anyone know what is wrong with my code?
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
setContentView(myVideoView);
You can not reference R.id.myvideoview before you set your Layout with setContentView
setContentView(R.layour.layout_with_videoview);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);

Not displaying videoview in full screen

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

Android: Cannot see video on HTC Hero 1.5

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.

Categories

Resources