Project example
Finally, I got a draft evidence-based concept for the job, so I'll talk about it here.
Layout Customization
The layout is set up in such a way where the light gray area is VideoView .

activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.videotest.MainActivity"> <VideoView android:id="@+id/videoview" android:layout_width="300dp" android:layout_height="200dp"/> <Button android:text="Play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/videoview" android:onClick="onButtonClick" android:id="@+id/button"/> </RelativeLayout>
Prepare a video clip
According to the documentation here . It uses the powerful ffmpeg command line tool to convert to what should play on all (hopefully?) Android devices. Read the answer I linked to get more explanation. I used a slightly modified version because I was getting errors with the original version.
ffmpeg -y -i input_file.avi -s 432x320 -b:v 384k -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -subq 6 -trellis 0 -refs 5 -bf 0 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -c:a aac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 -strict -2 output_file.mp4
I would definitely read a lot more about each of these options to find out which ones need to be adjusted, how much the video and sound quality goes.
Then rename output_file.mp4 to test.mp4 and put it in the Android /res/raw folder. Create a folder if it does not already exist.
The code
There is not much in the code. The video is played when you click the Play button. Thanks this answer for help.
MainActivity.java
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onButtonClick(View v) { VideoView videoview = (VideoView) findViewById(R.id.videoview); Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.test); videoview.setVideoURI(uri); videoview.start(); } }
Passed
It's all. Now you can play your video clip on a simulator or a real device.
Suragch Dec 09 '16 at 13:45 2016-12-09 13:45
source share