Example usage for android.media MediaPlayer MEDIA_ERROR_UNSUPPORTED

List of usage examples for android.media MediaPlayer MEDIA_ERROR_UNSUPPORTED

Introduction

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

Prototype

int MEDIA_ERROR_UNSUPPORTED

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

Click Source Link

Document

Bitstream is conforming to the related coding standard or file spec, but the media framework does not support the feature.

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   w w w.ja  v a2s .c  o  m
    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,
 * /*from   w  ww  .java2 s.  co  m*/
 * @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;/*from   w w w .j  a  va2 s .c  o  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 ww  w.  j  a va2  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: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 av  a 2 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;//from w w w .j  a  v  a2  s.c  o m
    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();
    }

}