question

guillaumel avatar image
guillaumel asked

VideoView crashes on Kindle Fire HD

Hi ! VideoView keeps crashing in KindleFire with the following trace : 11-05 14:06:21.655: E/AndroidRuntime(1490): Caused by: java.lang.NullPointerException 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.widget.MediaController$VolumeController.init(MediaController.java:967) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.widget.MediaController$VolumeController.access$700(MediaController.java:912) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.widget.MediaController.initControllerView(MediaController.java:370) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.widget.MediaController.onFinishInflate(MediaController.java:150) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.rInflate(LayoutInflater.java:729) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.rInflate(LayoutInflater.java:729) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 11-05 14:06:21.655: E/AndroidRuntime(1490): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 11-05 14:06:21.655: E/AndroidRuntime(1490): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:261) As we don't have access to source code, does anyone know how I can prevent this from happening ? Thanks
fire tablet
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Samuel@Amazon avatar image
Samuel@Amazon answered
Hi, We are looking in to this and we will notify you on this thread once we have an update. Thank you.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Samuel@Amazon avatar image
Samuel@Amazon answered
Hi, We need more information for looking in to this issue and there are no global issues found with Video View on Kindle Fire. NPE usually appears because the video resource is not being found. To debug further into this issue we need additional information(source). Can you please submit a contact us to Amazon with full logs and other details, one of our support engineers will assist you in this. Thanks for your patience.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mpaulkindle avatar image
mpaulkindle answered
Did anyone know what is the cause of this,I too have the same exception? please help
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mpaulkindle avatar image
mpaulkindle answered
Does anyone know what is the cause of this,I too have the same exception? the crash happens when android MediaController is used with MediaPlayerControl. Is MediaController not supported in Kindle Fire?My Kindle Fire version is 7.2.3_user_23330720. If i don't use MediaController the video plays. please help
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi mpaulkindle, Can you please post the sample code? What kind of media you are trying to play? Is that mp4?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mpaulkindle avatar image
mpaulkindle answered
Hi, Yes I am playing mp4.my code is lots and is integrated with the core product code.It works well in all other devices except Kindle fire. I have a VideoActivity class from which I call setContentView(R.layout.screen_video);screen_video.XML has a VideoView class extends SurfaceView implements MediaPlayerControl. the crash happens on call of setContentView(R.layout.screen_video); if i remove the media_controller .It will play the video .but without the medicontroller. screen_video.XML ---------------------------- that's my media_contoller.XML.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
I am successfully able to play mp4 with VideoView/MediaController.MediaPlayerControl in the same version of Kindle what are you trying there. Here is the code: -------------------------------------- VideoPlayer Activity ---------------------------------------------------- public class VideoPlayer extends Activity implements MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener { public static final String TAG = "VideoPlayer"; private VideoView mVideoView; private Uri mUri; private int mPositionWhenPaused = -1; private MediaController mMediaController; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Set the screen to landscape. this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); mVideoView = (VideoView) findViewById(R.id.video_view); //Video file mUri = Uri.parse(Environment.getExternalStorageDirectory() + "/test.mp4"); mMediaController = new MediaController(this); mVideoView.setMediaController(mMediaController); } public void onStart() { // Play Video mVideoView.setVideoURI(mUri); mVideoView.start(); super.onStart(); } public void onPause() { // Stop video when the activity is pause. mPositionWhenPaused = mVideoView.getCurrentPosition(); mVideoView.stopPlayback(); super.onPause(); } public void onResume() { // Resume video player if (mPositionWhenPaused >= 0) { mVideoView.seekTo(mPositionWhenPaused); mPositionWhenPaused = -1; } super.onResume(); } public boolean onError(MediaPlayer player, int arg1, int arg2) { return false; } public void onCompletion(MediaPlayer mp) { this.finish(); } } ------------------------------------ CustomerVideoView ----------------------------------------------- public class CustomerVideoView extends SurfaceView implements MediaController.MediaPlayerControl { private static String TAG = "customer.videoplayer"; private boolean pause; private boolean seekBackward; private boolean seekForward; private Uri videoUri; private MediaPlayer mediaPlayer; private Context context; private MediaPlayer.OnPreparedListener onPreparedListener; private int videoWidth; private int videoHeight; private MediaController mediaController; protected SurfaceHolder surfaceHolder; private SurfaceHolder.Callback surfaceHolderCallback = new SurfaceHolder.Callback() { public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { } public void surfaceCreated(SurfaceHolder holder) { surfaceHolder = holder; if (mediaPlayer != null) { mediaPlayer.setDisplay(surfaceHolder); resume(); } else { openVideo(); } } public void surfaceDestroyed(SurfaceHolder holder) { surfaceHolder = null; if (mediaController != null) { mediaController.hide(); } release(true); } }; private void release(boolean cleartargetstate) { if (mediaPlayer != null) { mediaPlayer.reset(); mediaPlayer.release(); mediaPlayer = null; } } public void resume() { if (surfaceHolder == null) { return; } if (mediaPlayer != null) { return; } openVideo(); } public CustomerVideoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.context = context; this.initVideoView(); } public CustomerVideoView(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; this.initVideoView(); } public CustomerVideoView(Context context) { super(context); this.context = context; this.initVideoView(); } @Override public boolean canPause() { return this.pause; } @Override public boolean canSeekBackward() { return this.seekBackward; } @Override public boolean canSeekForward() { return this.seekForward; } @Override public int getBufferPercentage() { return 0; } @Override public int getCurrentPosition() { return mediaPlayer!=null?mediaPlayer.getCurrentPosition():0; } @Override public int getDuration() { return mediaPlayer!=null?mediaPlayer.getDuration():0; } @Override public boolean isPlaying() { return false; } @Override public void pause() { } @Override public void seekTo(int mSec) { } @Override public void start() { } public void setVideoURI(Uri uri) { this.videoUri = uri; openVideo(); requestLayout(); invalidate(); } private void openVideo() { this.mediaPlayer = new MediaPlayer(); try { this.mediaPlayer.setDataSource(this.context, this.videoUri); } catch (Exception e) { Log.e(TAG, e.getMessage()); throw new RuntimeException(e); } this.mediaPlayer.prepareAsync(); this.mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); this.mediaPlayer.setOnPreparedListener(onPreparedListener); attachMediaController(); } private void attachMediaController() { if (mediaPlayer != null && mediaController != null) { mediaController.setMediaPlayer(this); View anchorView = this.getParent() instanceof View ? (View) this .getParent() : this; mediaController.setAnchorView(anchorView); mediaController.setEnabled(true); } } public void setMediaController(MediaController controller) { if (mediaController != null) { mediaController.hide(); } mediaController = controller; attachMediaController(); } public void setOnPreparedListener(MediaPlayer.OnPreparedListener onPreparedListener) { this.onPreparedListener = onPreparedListener; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = getDefaultSize(videoWidth, widthMeasureSpec); int height = getDefaultSize(videoHeight, heightMeasureSpec); if (videoWidth > 0 && videoHeight > 0) { if (videoWidth * height > width * videoHeight) { height = width * videoHeight / videoWidth; } else if (videoWidth * height < width * videoHeight) { width = height * videoWidth / videoHeight; } } Log.i(TAG, "setting size: " + width + "x" + height); setMeasuredDimension(width, height); } private void initVideoView() { videoWidth = 0; videoHeight = 0; getHolder().addCallback(surfaceHolderCallback); getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); setFocusable(true); setFocusableInTouchMode(true); requestFocus(); } } --------------------------------------- main.xml -------------------------------------------- ----------------------------------------------------------------------------------------------------------- You need to point your mp4 file in VideoPlayer class. If it does not solve your problem, please see if there is any error reported in ADB logcat.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mpaulkindle avatar image
mpaulkindle answered
Thanks a lot for your update. I was able to fix this. I removed the from my media_contoller.XML and it worked in kindle and all other devices. I don't know why we need this since we use custom mediacontoller class to set the mediacontoller for VideoView class.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.