Example usage for android.media MediaPlayer MEDIA_ERROR_IO

List of usage examples for android.media MediaPlayer MEDIA_ERROR_IO

Introduction

In this page you can find the example usage for android.media MediaPlayer MEDIA_ERROR_IO.

Prototype

int MEDIA_ERROR_IO

To view the source code for android.media MediaPlayer MEDIA_ERROR_IO.

Click Source Link

Document

File or network related operation errors.

Usage

From source file:org.y20k.transistor.PlayerService.java

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {

    switch (what) {
    case MediaPlayer.MEDIA_ERROR_UNKNOWN:
        Log.e(LOG_TAG, "Unknown media playback error");
        break;/*from ww w  . j a  va 2s .  c  om*/
    case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
        Log.e(LOG_TAG, "Connection to server lost");
        break;
    default:
        Log.e(LOG_TAG, "Generic audio playback error");
        break;
    }

    switch (extra) {
    case MediaPlayer.MEDIA_ERROR_IO:
        Log.e(LOG_TAG, "IO media error.");
        break;
    case MediaPlayer.MEDIA_ERROR_MALFORMED:
        Log.e(LOG_TAG, "Malformed media.");
        break;
    case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
        Log.e(LOG_TAG, "Unsupported content type");
        break;
    case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
        Log.e(LOG_TAG, "Media timeout");
        break;
    default:
        Log.e(LOG_TAG, "Other case of media playback error");
        break;
    }

    mp.reset();

    return true;
}

From source file:com.owncloud.android.media.MediaService.java

/**
 * Helper method to get an error message suitable to show to users for errors occurred in media playback,
 * /*  ww w  .j  av  a  2s  .c  om*/
 * @param context   A context to access string resources.
 * @param what      See {@link MediaPlayer.OnErrorListener#onError(MediaPlayer, int, int)
 * @param extra     See {@link MediaPlayer.OnErrorListener#onError(MediaPlayer, int, int)
 * @return          Message suitable to users.
 */
public static String getMessageForMediaError(Context context, int what, int extra) {
    int messageId;

    if (what == OC_MEDIA_ERROR) {
        messageId = extra;

    } else if (extra == MediaPlayer.MEDIA_ERROR_UNSUPPORTED) {
        /*  Added in API level 17
        Bitstream is conforming to the related coding standard or file spec,
        but the media framework does not support the feature.
        Constant Value: -1010 (0xfffffc0e)
         */
        messageId = R.string.media_err_unsupported;

    } else if (extra == MediaPlayer.MEDIA_ERROR_IO) {
        /*  Added in API level 17
        File or network related operation errors.
        Constant Value: -1004 (0xfffffc14) 
         */
        messageId = R.string.media_err_io;

    } else if (extra == MediaPlayer.MEDIA_ERROR_MALFORMED) {
        /*  Added in API level 17
        Bitstream is not conforming to the related coding standard or file spec.
        Constant Value: -1007 (0xfffffc11) 
         */
        messageId = R.string.media_err_malformed;

    } else if (extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
        /*  Added in API level 17
        Some operation takes too long to complete, usually more than 3-5 seconds.
        Constant Value: -110 (0xffffff92)
        */
        messageId = R.string.media_err_timeout;

    } else if (what == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
        /*  Added in API level 3
        The video is streamed and its container is not valid for progressive playback i.e the video's index
        (e.g moov atom) is not at the start of the file.
        Constant Value: 200 (0x000000c8)
        */
        messageId = R.string.media_err_invalid_progressive_playback;

    } else {
        /*  MediaPlayer.MEDIA_ERROR_UNKNOWN
        Added in API level 1
        Unspecified media player error.
        Constant Value: 1 (0x00000001)
        */
        /*  MediaPlayer.MEDIA_ERROR_SERVER_DIED)
        Added in API level 1
        Media server died. In this case, the application must release the MediaPlayer
        object and instantiate a new one.
        Constant Value: 100 (0x00000064) 
         */
        messageId = R.string.media_err_unknown;
    }
    return context.getString(messageId);
}

From source file:com.reallynourl.nourl.fmpfoldermusicplayer.backend.MediaService.java

@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    mIsPreparedToPlay = false;/*  ww w  .j a  va 2  s.  co  m*/
    String message = "undefined media player error";
    switch (what) {
    case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
        message = "The media server died. This is probably not my fault, but playback had to be stopped, feel free to start it again.";
        break;
    case MediaPlayer.MEDIA_ERROR_UNKNOWN:
        switch (extra) {
        case MediaPlayer.MEDIA_ERROR_IO:
            message = "There was an error reading the current media file.";
            break;
        case MediaPlayer.MEDIA_ERROR_MALFORMED:
            message = "The file is probably not a valid audio file.";
            break;
        case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
            message = "The current file is not supported by your device, I'm really sorry.";
            break;
        case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
            message = "The media player timed out.";
            break;
        case MediaService.MEDIA_ERROR_SYSTEM:
            message = "A low level system error occured. This should have never happened, sorry :/";
            break;
        }
        break;
    }
    releasePlayer();
    Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
    return false;
}

From source file:at.wada811.app.fragment.VideoFragment.java

private void initMediaPlayer() {
    LogUtils.i();//from w ww .j a v  a2  s.  c  o  m
    if (getArguments().keySet().contains(KEY_RES_ID)) {
        mMediaPlayer = MediaPlayer.create(getActivity(), getArguments().getInt(KEY_RES_ID));
    } else {
        mMediaPlayer = new MediaPlayer();
    }
    mMediaPlayer.setOnVideoSizeChangedListener(this);
    mMediaPlayer.setOnBufferingUpdateListener(this);
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setOnCompletionListener(this);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setOnInfoListener(new OnInfoListener() {
        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            switch (what) {
            case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
                LogUtils.i("MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING");
                break;
            case MediaPlayer.MEDIA_INFO_BUFFERING_END:
                LogUtils.i("MediaPlayer.MEDIA_INFO_BUFFERING_END");
                break;
            case MediaPlayer.MEDIA_INFO_BUFFERING_START:
                LogUtils.i("MediaPlayer.MEDIA_INFO_BUFFERING_START");
                break;
            case MediaPlayer.MEDIA_INFO_METADATA_UPDATE:
                LogUtils.i("MediaPlayer.MEDIA_INFO_METADATA_UPDATE");
                break;
            case MediaPlayer.MEDIA_INFO_NOT_SEEKABLE:
                LogUtils.i("MediaPlayer.MEDIA_INFO_NOT_SEEKABLE");
                break;
            case MediaPlayer.MEDIA_INFO_SUBTITLE_TIMED_OUT:
                LogUtils.i("MediaPlayer.MEDIA_INFO_SUBTITLE_TIMED_OUT");
                break;
            case MediaPlayer.MEDIA_INFO_UNSUPPORTED_SUBTITLE:
                LogUtils.i("MediaPlayer.MEDIA_INFO_UNSUPPORTED_SUBTITLE");
                break;
            case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
                LogUtils.i("MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START");
                break;
            case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING:
                LogUtils.i("MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING");
                break;
            case MediaPlayer.MEDIA_INFO_UNKNOWN:
            default:
                LogUtils.i("MediaPlayer.MEDIA_INFO_UNKNOWN");
                break;
            }
            LogUtils.d("extra: " + extra);
            return false;
        }
    });
    mMediaPlayer.setOnErrorListener(new OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            switch (what) {
            case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_SERVER_DIED");
                break;
            case MediaPlayer.MEDIA_ERROR_UNKNOWN:
            default:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_UNKNOWN");
                break;
            }
            switch (extra) {
            case MediaPlayer.MEDIA_ERROR_IO:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_IO");
                break;
            case MediaPlayer.MEDIA_ERROR_MALFORMED:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_MALFORMED");
                break;
            case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK");
                break;
            case MediaPlayer.MEDIA_ERROR_TIMED_OUT:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_TIMED_OUT");
                break;
            case MediaPlayer.MEDIA_ERROR_UNSUPPORTED:
                LogUtils.e("MediaPlayer.MEDIA_ERROR_UNSUPPORTED");
                break;
            default:
                LogUtils.e("extra: " + extra);
                break;
            }
            return false;
        }
    });
    mCallback.onActivityCreated(this);
}

From source file:com.android.onemedia.playback.LocalRenderer.java

@Override
public boolean onError(MediaPlayer player, int what, int extra) {
    if (!isCurrentPlayer(player)) {
        return false;
    }/*ww  w  .  j a  v a  2 s  .c  om*/
    if (DEBUG) {
        Log.d(TAG, mDebugId + ": Entered error state, what: " + what + " extra: " + extra);
    }
    synchronized (mErrorLock) {
        ++mErrorId;
        mError = new PlaybackError();
        mError.type = what;
        mError.extra = extra;
    }

    if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN && extra == MediaPlayer.MEDIA_ERROR_IO && mContent != null
            && mContent.source.startsWith("http")) {
        HttpGet request = new HttpGet(mContent.source);
        if (mContent.headers != null) {
            for (String key : mContent.headers.keySet()) {
                request.addHeader(key, mContent.headers.get(key));
            }
        }
        synchronized (mErrorLock) {
            if (mErrorRetriever != null) {
                mErrorRetriever.cancelRequestLocked(false);
            }
            mErrorRetriever = new AsyncErrorRetriever(mErrorId);
            mErrorRetriever.execute(request);
        }
    } else {
        setError(what, extra, null, null);
    }
    return true;
}

From source file:fm.krui.kruifm.StreamService.java

/**
 * All MediaPlayer errors will call this method with details.
 * @param mp MediaPlayer object that threw the error
 * @param what int identifier of error type
 * @param extra int identifier of error code
 * @return true if error was handled by this method, false if not.
 */// w  w w .j  a v a2 s.c  o  m
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {

    this.mp = buildAudioPlayer();

    // Log the error
    Log.e(TAG, "*** MediaPlayer has encountered a fatal error.");
    String errorType = "";
    String errorCode = "";
    if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN) {
        errorType = "UNKNOWN ERROR";
    } else if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
        errorType = "SERVER DIED";
    }
    Log.e(TAG, "*** Error Type: " + errorType);

    if (extra == MediaPlayer.MEDIA_ERROR_IO) {
        errorCode = "IO ERROR";
    } else if (extra == MediaPlayer.MEDIA_ERROR_MALFORMED) {
        errorCode = "MALFORMED MEDIA";
    } else if (extra == MediaPlayer.MEDIA_ERROR_UNSUPPORTED) {
        errorCode = "UNSUPPORTED MEDIA";
    } else if (extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
        errorCode = "MEDIA TIMED OUT";
    }
    Log.e(TAG, "*** Error Code: " + errorCode);
    // FIXME: UGLY. Clean this up.
    updateStreamStatus("Error! Type: " + errorType + " / Code: " + errorCode, false);
    isPrepared = false;
    return false;
}

From source file:audio.lisn.adapter.StoreBookViewAdapter.java

private void playPreview() {
    isLoadingPreview = true;//  w w w  . ja v  a  2  s .  c om
    isPlayingPreview = false;
    pausePlayer();
    notifyDataSetChanged();

    if (connectionDetector.isConnectingToInternet()) {
        if (mediaPlayer == null) {
            mediaPlayer = new MediaPlayer();
        }
        if (mediaPlayer.isPlaying()) {
            mediaPlayer.stop();
            if (timerUpdateThread != null) {
                timerUpdateThread.interrupt();
            }
        }

        mediaPlayer.reset();

        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        try {
            mediaPlayer.setDataSource(selectedAudioBook.getPreview_audio());
        } catch (IOException e) {
            Log.v("playPreview", "IOException" + e.getMessage());

            e.printStackTrace();
        }
        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                isPlayingPreview = true;
                isLoadingPreview = false;
                startTimer();
                mp.start();
                notifyDataSetChanged();
            }
        });
        mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
                notifyDataSetChanged();

                String msg = "";

                if (extra == MediaPlayer.MEDIA_ERROR_IO) {
                    msg = "MEDIA_ERROR_IO";
                } else if (extra == MediaPlayer.MEDIA_ERROR_MALFORMED) {
                    msg = "MEDIA_ERROR_MALFORMED";
                } else if (extra == MediaPlayer.MEDIA_ERROR_UNSUPPORTED) {
                    msg = "MEDIA_ERROR_UNSUPPORTED";
                } else if (extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
                    msg = "MEDIA_ERROR_TIMED_OUT";
                } else {
                    msg = "video_error_unknown_error";
                }
                showErrorMessage(msg);

                return false;
            }
        });
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                isPlayingPreview = false;
                isLoadingPreview = false;
                stopTimer();
                notifyDataSetChanged();
            }
        });
        try {
            mediaPlayer.prepareAsync(); // prepare async to not block main
        } catch (Exception e) {
            showErrorMessage(e.getMessage());

            isPlayingPreview = false;
            isLoadingPreview = false;
            stopTimer();
            notifyDataSetChanged();
        }

    } else {

        AlertDialog.Builder builder = new AlertDialog.Builder(selectedView.getContext());
        builder.setTitle(R.string.NO_INTERNET_TITLE).setMessage(R.string.NO_INTERNET_MESSAGE)
                .setPositiveButton(R.string.BUTTON_OK, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // FIRE ZE MISSILES!
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.show();
    }

}

From source file:com.shinymayhem.radiopresets.ServiceRadioPlayer.java

public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
    if (LOCAL_LOGV)
        log("onError()", "e");
    //check if mediaPlayer is or needs to be released

    if (mediaPlayer != null) {
        stopAndReleasePlayer(mediaPlayer);
        mediaPlayer = null;//from w ww  .j  a va  2s .  c o  m
        mMediaPlayer = null;
    }
    String oldState = mCurrentPlayerState;
    mCurrentPlayerState = ServiceRadioPlayer.STATE_ERROR;
    //set 'now playing' to error
    stopInfo(getResources().getString(R.string.status_error));
    String title;
    String text;
    boolean unknown = false;
    if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN && extra == -2147483648) {
        title = getResources().getString(R.string.error_title);
        text = getResources().getString(R.string.error_url_format);
    } else if (extra == MediaPlayer.MEDIA_ERROR_IO) {
        title = getResources().getString(R.string.error_title);
        text = getResources().getString(R.string.error_media_io);
    } else if (extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
        title = getResources().getString(R.string.error_title);
        text = getResources().getString(R.string.error_timed_out);
    } else //unknown/unhandled error
    {
        title = getResources().getString(R.string.error_title);
        text = getResources().getString(R.string.error_unknown);
        this.getErrorNotification(title, text);
        unknown = true;

    }
    //show user error notification
    this.getErrorNotification(title, text);

    if (unknown) {
        text += ", " + String.valueOf(what) + ":" + String.valueOf(extra);
    }
    if (LOCAL_LOGD)
        log("Previous:" + oldState, "e");
    log(text, "e");

    return false;

}

From source file:co.shunya.gita.player.MusicService.java

/**
 * Called when there's an error playing media. When this happens, the media player goes to
 * the Error state. We warn the user about the error and reset the media player.
 *//*from   w w  w  .  ja  v  a2s.c o  m*/
public boolean onError(MediaPlayer mp, int what, int extra) {
    Log.e(TAG, "Error: what=" + String.valueOf(what) + ", extra=" + String.valueOf(extra));
    if (extra == MediaPlayer.MEDIA_ERROR_IO) {
        Toast.makeText(getApplicationContext(),
                "Connectivity Problem" + (mIsStreaming ? "\nError Connecting with internet" : ""),
                Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(getApplicationContext(), "Unknon Error\nMedia Player resetting", Toast.LENGTH_SHORT)
                .show();
    }

    setState(State.Stopped);
    relaxResources(true);
    giveUpAudioFocus();
    return true; // true indicates we handled the error
}

From source file:androidx.media.widget.VideoView2.java

private void openVideo(Uri uri, Map<String, String> headers) {
    resetPlayer();//from   www  . ja  v a2s  .  c o  m
    if (isRemotePlayback()) {
        // TODO (b/77158231)
        // mRoutePlayer.openVideo(dsd);
        return;
    }

    try {
        Log.d(TAG, "openVideo(): creating new MediaPlayer instance.");
        mMediaPlayer = new MediaPlayer();
        mSurfaceView.setMediaPlayer(mMediaPlayer);
        mTextureView.setMediaPlayer(mMediaPlayer);
        mCurrentView.assignSurfaceToMediaPlayer(mMediaPlayer);

        final Context context = getContext();
        // TODO: Add timely firing logic for more accurate sync between CC and video frame
        // mSubtitleController = new SubtitleController(context);
        // mSubtitleController.registerRenderer(new ClosedCaptionRenderer(context));
        // mSubtitleController.setAnchor((SubtitleController.Anchor) mSubtitleView);

        mMediaPlayer.setOnPreparedListener(mPreparedListener);
        mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
        mMediaPlayer.setOnCompletionListener(mCompletionListener);
        mMediaPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
        mMediaPlayer.setOnErrorListener(mErrorListener);
        mMediaPlayer.setOnInfoListener(mInfoListener);
        mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);

        mCurrentBufferPercentage = -1;
        mMediaPlayer.setDataSource(getContext(), uri, headers);
        mMediaPlayer.setAudioAttributes(mAudioAttributes);
        // mMediaPlayer.setOnSubtitleDataListener(mSubtitleListener);
        // we don't set the target state here either, but preserve the
        // target state that was there before.
        mCurrentState = STATE_PREPARING;
        mMediaPlayer.prepareAsync();

        // Save file name as title since the file may not have a title Metadata.
        mTitle = uri.getPath();
        String scheme = uri.getScheme();
        if (scheme != null && scheme.equals("file")) {
            mTitle = uri.getLastPathSegment();
        }
        mRetriever = new MediaMetadataRetriever();
        mRetriever.setDataSource(getContext(), uri);

        if (DEBUG) {
            Log.d(TAG, "openVideo(). mCurrentState=" + mCurrentState + ", mTargetState=" + mTargetState);
        }
    } catch (IOException | IllegalArgumentException ex) {
        Log.w(TAG, "Unable to open content: " + uri, ex);
        mCurrentState = STATE_ERROR;
        mTargetState = STATE_ERROR;
        mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, MediaPlayer.MEDIA_ERROR_IO);
    }
}