主要功能

直播:支持 RTMP 协议的流媒体播放

示例代码

public class LivePlayerActivity extends Activity {

    private static final String TAG = "LivePlayerActivity";

    VHLivePlayer mPlayer;
    VHVideoPlayerView mVideoPlayer;
    MyReceiver myReceiver;
    private String roomId = "";
    private String accessToken = "";
    //data
    String currentDPI = "";
    List<String> dipList = new ArrayList<>();
    int drawmode = IVHVideoPlayer.DRAW_MODE_NONE;
    //view
    ImageView mPlayBtn;
    ProgressBar mLoadingPB;
    TextView mSpeedTV;
    private DPIPopu popu;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        roomId = getIntent().getStringExtra("roomid");
        accessToken = getIntent().getStringExtra("token");
        setContentView(R.layout.player_layout);
        mVideoPlayer = (VHVideoPlayerView) this.findViewById(R.id.player);
        mPlayer = new VHLivePlayer.Builder().videoPlayer(mVideoPlayer).listener(new MyListener()).build();

        mPlayBtn = (ImageView) this.findViewById(R.id.btn_play);
        mLoadingPB = (ProgressBar) this.findViewById(R.id.pb_loading);
        mSpeedTV = (TextView) this.findViewById(R.id.tv_speed);
        popu = new DPIPopu(this);
        popu.setOnDPIChangedListener(new DPIPopu.OnDPIChangedListener() {
            @Override
            public void onDPIChanged(String dpi) {
                mPlayer.setDPI(dpi);
                currentDPI = dpi;
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (mPlayer.isPlaying())
            mPlayer.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mPlayer.resumeAble())
            mPlayer.resume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPlayer.release();
        unRegistReceiver();
    }

    public void play(View view) {
        if (mPlayer.isPlaying()) {
            mPlayer.stop();
        } else {
            if (mPlayer.resumeAble())
                mPlayer.resume();
            else
                mPlayer.start(roomId, accessToken);
        }
    }

    public void changeDPI(View view) {
        popu.showAtLocation(getWindow().getDecorView().findViewById(android.R.id.content), Gravity.CENTER, 0, 0);
    }

    public void changeMode(View view) {
        mVideoPlayer.setDrawMode(++drawmode % 3);
    }

    class MyListener implements VHPlayerListener {

        @Override
        public void onEvent(int event, String msg) {

            switch (event) {
                case IVHLivePlayer.EVENT_STATUS_STARTING:
                    break;
                case IVHLivePlayer.EVENT_STATUS_STARTED:
                    mPlayBtn.setImageResource(R.mipmap.icon_pause_bro);
                    break;
                case IVHLivePlayer.EVENT_STATUS_STOPED:
                    mPlayBtn.setImageResource(R.mipmap.icon_start_bro);
                    break;
                case IVHLivePlayer.EVENT_DPI_LIST:
                    Log.i(TAG, "DPILIST:" + msg);
                    try {
                        JSONArray array = new JSONArray(msg);
                        if (array != null && array.length() > 0) {
                            dipList.clear();
                            for (int i = 0; i < array.length(); i++) {
                                dipList.add((String) array.get(i));
                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    popu.notifyDataSetChanged(currentDPI, dipList);
                    break;
                case IVHLivePlayer.EVENT_DPI_CHANGED:
                    Log.i(TAG, "DPI:" + msg);
                    if (!msg.equals(currentDPI))
                        currentDPI = msg;
                    popu.notifyDataSetChanged(currentDPI, dipList);
                    break;
                case IVHLivePlayer.EVENT_DOWNLOAD_SPEED:
                    mSpeedTV.setText(msg + "kb/s");
                    break;
                case IVHLivePlayer.EVENT_START_BUFFER:
                    mLoadingPB.setVisibility(View.VISIBLE);
                    break;
                case IVHLivePlayer.EVENT_STOP_BUFFER:
                    mLoadingPB.setVisibility(View.GONE);
                    break;
                case IVHLivePlayer.EVENT_VIDEO_SIZE_CHANGED:
                    Log.i(TAG, msg);
                    break;
            }


        }

        @Override
        public void onError(int errorCode, String msg) {
            mLoadingPB.setVisibility(View.GONE);
            Log.i(TAG, "errorCode:" + errorCode + ",msg:" + msg);
            switch (errorCode) {
                case IVHLivePlayer.ERROR_CONNECT:
                    break;
                case IVHLivePlayer.ERROR_SEND:
                    break;
                case IVHLivePlayer.ERROR_PARAM:
                    break;
            }

        }
    }
}

下载地址

http://www.vhallyun.com/document/document/download