You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "dharmendra sharma (JIRA)" <ji...@apache.org> on 2016/02/04 08:20:39 UTC
[jira] [Commented] (CB-6144) Media Plugin throws Null Pointer
Exception - Android 4.4.2
[ https://issues.apache.org/jira/browse/CB-6144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15131856#comment-15131856 ]
dharmendra sharma commented on CB-6144:
---------------------------------------
Probably your recorded file is not reaching to your media player. Please make sure that file you trying to play is exist in your device.
> Media Plugin throws Null Pointer Exception - Android 4.4.2
> ----------------------------------------------------------
>
> Key: CB-6144
> URL: https://issues.apache.org/jira/browse/CB-6144
> Project: Apache Cordova
> Issue Type: Bug
> Components: Plugin Media
> Affects Versions: 3.3.0
> Environment: Android 4.4.2 - Nexus 7
> Reporter: Ashwin Desai
> Attachments: stacktrace.txt
>
>
> Here's my scenario
> 1) Start Recording using the Media plugin
> theMedia = new Media(localFile, mediaSuccess, mediaError, mediaStatus);
> theMedia.startRecord();
> 2) Continue for 1 minute
> 3) Stop recording and confirm that the file exists on the sdcard.
> theMedia.stopRecord();
> 4) Play the file recorded in steps 1 - 3.
> Stacktrace is attached to the issue.
> theMedia.play();
> 5) The plugin throws a Null Pointer Exception at the line marked with //--> THROWS A NPE.
> 6) I have also shown a possible solution at the line marked with // POSSIBLE SOLUTION.
> <code>
> /**
> * attempts to initialize the media player for playback
> * @param file the file to play
> * @return false if player not ready, reports if in wrong mode or state
> */
> private boolean readyPlayer(String file) {
> if (playMode()) {
> switch (this.state) {
> case MEDIA_NONE:
> if (this.player == null) {
> this.player = new MediaPlayer();
> }
> try {
> this.loadAudioFile(file);
> } catch (Exception e) {
> this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
> }
> return false;
> case MEDIA_LOADING:
> //cordova js is not aware of MEDIA_LOADING, so we send MEDIA_STARTING instead
> Log.d(LOG_TAG, "AudioPlayer Loading: startPlaying() called during media preparation: " + STATE.MEDIA_STARTING.ordinal());
> this.prepareOnly = false;
> return false;
> case MEDIA_STARTING:
> case MEDIA_RUNNING:
> case MEDIA_PAUSED:
> return true;
> case MEDIA_STOPPED:
> //if we are readying the same file
> if (this.audioFile.compareTo(file) == 0) {
> //reset the audio file
> /*** POSSIBLE SOLUTION: TO FIX NPE */
> if (player == null) {
> player = new MediaPlayer();
> try {
> this.loadAudioFile(file);
> } catch (Exception e) {
> this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
> }
> }
> player.seekTo(0); //---> THROWS NULL POINTER EXCEPTION
> player.pause();
> return true;
> } else {
> //reset the player
> this.player.reset();
> try {
> this.loadAudioFile(file);
> } catch (Exception e) {
> this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
> }
> //if we had to prepare= the file, we won't be in the correct state for playback
> return false;
> }
> default:
> Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: " + this.state);
> this.handler.webView.sendJavascript("cordova.require('org.apache.cordova.media.Media').onStatus('" + this.id + "', " + MEDIA_ERROR + ", { \"code\":" + MEDIA_ERR_ABORTED + "});");
> }
> }
> return false;
> }
> </code>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org