Want to resize video in surface view
I play videos in Media Player using Surface view and video holder ...
// but when implementing MediaPlayerControl on some devices they say that Micromax, iball, Akash tablet, it gives an abstract method error, inaccessible to track ACRA error tracking.
Now I want to have a solution to the mentioned problems:
How to make the controls of the multimedia player active in all devices without fail due to the abstract method, as for the media controller in some devices.
How to resize the image on the surface.
The code runs f9 on the galaxy samsung gt p1000 OS 2.2 and the cheaper WorldTeck device, etc.
But on Creative ziio 7 OS version 2.2.1 (480 * 800), the resolution density of 160 dpi video seems to be increased and disconnected from the edges.
The code is shown below:
public class VideoViewerActivity extends Activity implements
OnBufferingUpdateListener, OnCompletionListener, OnPreparedListener,
OnVideoSizeChangedListener, SurfaceHolder.Callback {
private static final String TAG = "MediaPlayerDemo";
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path = "";
private Bundle extras;
private static final String MEDIA = "media";
private static final int LOCAL_AUDIO = 1;
private static final int STREAM_AUDIO = 2;
private static final int RESOURCES_AUDIO = 3;
private static final int LOCAL_VIDEO = 4;
private static final int STREAM_VIDEO = 5;
private boolean mIsVideoSizeKnown = false;
private boolean mIsVideoReadyToBePlayed = false;
private Context context;
private final Handler handler = new Handler();
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.video_layout);
context = this;
path = getIntent().getExtras().getString("media");
Log.v("arpit", "path " + path);
mPreview = (SurfaceView) findViewById(R.id.surfaceview1);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();
}
private void playVideo() {
doCleanUp();
try {
File f = new File(path);
RandomAccessFile randomAccessFile = new RandomAccessFile(f, "r");
FileDescriptor fileDescriptor = randomAccessFile.getFD();
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(fileDescriptor, Constant.key1.length
+ Data.deviceID.length(), f.length());
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setScreenOnWhilePlaying(true);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
Toast.makeText(context, "supported video was not found",
Toast.LENGTH_SHORT).show();
finish();
}
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
Log.v(TAG, "onVideoSizeChanged called");
if (width == 0 || height == 0) {
Log.e(TAG, "invalid video width(" + width + ") or height(" + height
+ ")");
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
public void surfaceDestroyed(SurfaceHolder surfaceholder) {
Log.d(TAG, "surfaceDestroyed called");
}
public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG, "surfaceCreated called");
playVideo();
}
private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
mIsVideoSizeKnown = false;
}
private void startVideoPlayback() {
Log.v(TAG, "startVideoPlayback");
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
}