Created
August 30, 2017 09:32
-
-
Save engr-erum/0c916b638dc83cc2be0b1debeacf2c81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<VideoView | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:id="@+id/videoView" | |
android:layout_gravity="center" /> | |
</LinearLayout> | |
public class MainActivity extends AppCompatActivity { | |
private VideoView videoView; | |
private MediaController mediaController; | |
private int position = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
videoView = (VideoView) findViewById(R.id.videoView); | |
if (mediaController == null) { | |
mediaController = new MediaController(MainActivity.this); | |
mediaController.setAnchorView(videoView); | |
videoView.setMediaController(mediaController); | |
} | |
try { | |
File mainDir = new File(Environment.getExternalStorageDirectory(), "/recWed_Aug_30_12_18_35_GMT+05_00_2017.mp4"); | |
String url = mainDir.toString(); | |
Log.d(MainActivity.class.getName(),"Uri.parse(url):"+url); | |
videoView.setVideoPath(url); | |
} catch (Exception e) { | |
Log.e("Error", e.getMessage()); | |
e.printStackTrace(); | |
} | |
videoView.requestFocus(); | |
videoView.start(); | |
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { | |
public void onPrepared(MediaPlayer mediaPlayer) { | |
videoView.seekTo(position); | |
if (position == 0) { | |
videoView.start(); | |
} | |
mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() { | |
@Override | |
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { | |
mediaController.setAnchorView(videoView); | |
} | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment