当前位置: 首页>>代码示例>>Java>>正文


Java MediaPlayer类代码示例

本文整理汇总了Java中net.protyposis.android.mediaplayer.MediaPlayer的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer类的具体用法?Java MediaPlayer怎么用?Java MediaPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MediaPlayer类属于net.protyposis.android.mediaplayer包,在下文中一共展示了MediaPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onPrepared

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onPrepared(MediaPlayer mp) {
    mCurrentState = STATE_PREPARED;

    setPlaybackSpeed(mPlaybackSpeedWhenPrepared);

    if(mOnPreparedListener != null) {
        mOnPreparedListener.onPrepared(mp);
    }

    int seekToPosition = mSeekWhenPrepared;  // mSeekWhenPrepared may be changed after seekTo() call
    if (seekToPosition != 0) {
        seekTo(seekToPosition);
    }

    if(mTargetState == STATE_PLAYING) {
        start();
    }
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:20,代码来源:MediaPlayerExtendedView.java

示例2: onCompletion

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onCompletion(MediaPlayer mp) {
    mCurrentState = STATE_PLAYBACK_COMPLETED;
    mTargetState = STATE_PLAYBACK_COMPLETED;
    if(mOnCompletionListener != null) {
        mOnCompletionListener.onCompletion(mp);
    }
    stayAwake(false);
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:10,代码来源:MediaPlayerExtendedView.java

示例3: onError

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    mCurrentState = STATE_ERROR;
    mTargetState = STATE_ERROR;
    if(mOnErrorListener != null) {
        return mOnErrorListener.onError(mp, what, extra);
    }
    return true;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:10,代码来源:MediaPlayerExtendedView.java

示例4: onInfo

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
    if(mOnInfoListener != null) {
        return mOnInfoListener.onInfo(mp, what, extra);
    }
    return true;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:8,代码来源:MediaPlayerExtendedView.java

示例5: openVideo

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
private void openVideo() {
    if (mSource == null || mInputSurfaceHolder == null) {
        // not ready for playback yet, will be called again later
        return;
    }

    release();

    mPlayer = new MediaPlayer();
    mPlayer.setSurface(getInputHolder().getSurface());
    mPlayer.setOnPreparedListener(mPreparedListener);
    mPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
    mPlayer.setOnSeekListener(mSeekListener);
    mPlayer.setOnSeekCompleteListener(mSeekCompleteListener);
    mPlayer.setOnCompletionListener(mCompletionListener);
    mPlayer.setOnErrorListener(mErrorListener);
    mPlayer.setOnInfoListener(mInfoListener);

    // Create a handler for the error message in case an exceptions happens in the following thread
    final Handler exceptionHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            mCurrentState = STATE_ERROR;
            mTargetState = STATE_ERROR;
            mErrorListener.onError(mPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
            return true;
        }
    });

    // Set the data source asynchronously as this might take a while, e.g. is data has to be
    // requested from the network/internet.
    // IMPORTANT:
    // We use a Thread instead of an AsyncTask for performance reasons, because threads started
    // in an AsyncTask perform much worse, no matter the priority the Thread gets (unless the
    // AsyncTask's priority is elevated before creating the Thread).
    // See comment in MediaPlayer#prepareAsync for detailed explanation.
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                mPlayer.setDataSource(mSource);

                // Async prepare spawns another thread inside this thread which really isn't
                // necessary; we call this method anyway because of the events it triggers
                // when it fails, and to stay in sync which the Android VideoView that does
                // the same.
                mPlayer.prepareAsync();
                mCurrentState = STATE_PREPARING;

                Log.d(TAG, "video opened");
            } catch (IOException e) {
                Log.e(TAG, "video open failed", e);

                // Send message to the handler that an error occurred
                // (we don't need a message id as the handler only handles this single message)
                exceptionHandler.sendEmptyMessage(0);
            }
        }
    }).start();
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:61,代码来源:MediaPlayerExtendedView.java

示例6: setOnPreparedListener

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnPreparedListener(MediaPlayer.OnPreparedListener l) {
    this.mOnPreparedListener = l;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例7: setOnSeekListener

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnSeekListener(MediaPlayer.OnSeekListener l) {
    this.mOnSeekListener = l;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例8: setOnSeekCompleteListener

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnSeekCompleteListener(MediaPlayer.OnSeekCompleteListener l) {
    this.mOnSeekCompleteListener = l;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例9: setOnCompletionListener

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例10: setOnErrorListener

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnErrorListener(MediaPlayer.OnErrorListener l) {
    this.mOnErrorListener = l;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例11: setOnInfoListener

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setOnInfoListener(MediaPlayer.OnInfoListener l) {
    this.mOnInfoListener = l;
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例12: getSeekMode

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public MediaPlayer.SeekMode getSeekMode() {
    return mPlayer.getSeekMode();
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例13: setSeekMode

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
public void setSeekMode(MediaPlayer.SeekMode seekMode) {
    mPlayer.setSeekMode(seekMode);
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:4,代码来源:MediaPlayerExtendedView.java

示例14: onVideoSizeChanged

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    updateResolution(width, height);
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:5,代码来源:MediaPlayerExtendedView.java

示例15: onSeek

import net.protyposis.android.mediaplayer.MediaPlayer; //导入依赖的package包/类
@Override
public void onSeek(MediaPlayer mp) {
    if(mOnSeekListener != null) {
        mOnSeekListener.onSeek(mp);
    }
}
 
开发者ID:protyposis,项目名称:Spectaculum,代码行数:7,代码来源:MediaPlayerExtendedView.java


注:本文中的net.protyposis.android.mediaplayer.MediaPlayer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。