I am trying my hands at Android App Development and facing some issues related to VideoView. I am using animator to scale my image. Code is as below:
MainActivity.java
private MediaPlayer mediaPlayer;
private SurfaceHolder vidHolder;
private SurfaceView vidSurface;
private VideoView videoView;
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.VideoView);
try {
Uri videoURL = Uri.parse(vidAddress);
videoView.setVideoURI(videoURL);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoView.requestFocus();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoView.start();
}
});
ImageView imageView = (ImageView) findViewById(R.id.imageView);
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.image_anim);
set.setTarget(imageView);
set.start();
}
activity_main.xml
<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"
android:background="#000000"
tools:context=".MainActivity" >
<VideoView
android:id="@+id/VideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@raw/logo"
android:visibility="visible"/>
</RelativeLayout>
image_anim.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="together">
<objectAnimator
android:propertyName="scaleX"
android:duration="10000"
android:valueFrom="1"
android:startOffset="5000"
android:valueTo="2"
android:valueType="floatType"/>
<objectAnimator
android:propertyName="scaleY"
android:duration="10000"
android:valueFrom="1"
android:startOffset="5000"
android:valueTo="2"
android:valueType="floatType"/>
</set>
The image displays fine when activity is started. But as and when it scales, I cannot see the image beyond its original dimensions. In other words, it gets cropped on beyond the area of the original dimensions.
I believe it is somewhat related to the following issue with VideoView but have no idea how to resolve it.
https://stackoverflow.com/a/22101290/3530685
For better understanding, this is what is happening
Scaling happens fine if I remove VideoView. How can I do properly scale image without the image getting cropped due to VideoView?
Edit: I tested it on another device with Android 5.1.1 and it works fine. But does not work fine in emulator or device with Android 4.0.4