package com.example.videoplaysdcard;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView videoView_player;
private static final String TAG="com.example.videoplaysdcard.MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUIElements();
playVideoFile("/mnt/sdcard/backups/p.mp4");
}
private void initUIElements() {
videoView_player = (VideoView) findViewById(R.id.videoView_player);
}
private void playVideoFile(String sdCardPath) {
try{
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView_player);
mc.setMediaPlayer(videoView_player);
videoView_player.setMediaController(mc);
videoView_player.setVideoPath(sdCardPath);
videoView_player.requestFocus();
videoView_player.start();
}catch(Exception e){
Log.e(TAG,e.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView videoView_player;
private static final String TAG="com.example.videoplaysdcard.MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initUIElements();
playVideoFile("/mnt/sdcard/backups/p.mp4");
}
private void initUIElements() {
videoView_player = (VideoView) findViewById(R.id.videoView_player);
}
private void playVideoFile(String sdCardPath) {
try{
MediaController mc = new MediaController(this);
mc.setAnchorView(videoView_player);
mc.setMediaPlayer(videoView_player);
videoView_player.setMediaController(mc);
videoView_player.setVideoPath(sdCardPath);
videoView_player.requestFocus();
videoView_player.start();
}catch(Exception e){
Log.e(TAG,e.toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
No comments:
Post a Comment