Giter VIP home page Giter VIP logo

livepublisher's Introduction

LivePublisher

Android RTMP推流程序。

使用Camera+AudioRecord获取原始音视频数据,进行x264+faac对进行实时编码,然后通过librtmp上传至流媒体服务器。 自己做着玩的,java层只需要保留PublishNativeJni.java,其他的可以随意封装。 MediaCodec编码实现:https://github.com/EarthXiang/HardWareLive

创建推流器:

    //分辨率:480x320 fps:25 码率:480k 音频采样率:44.1k 默认摄像头:后置
    //如果设备不支持这些参数会自动对参数进行调整,满足设备的支持。
    LivePusher livePusher = new LivePusher(480, 320, 480000, 25, 44100,CameraInfo.CAMERA_FACING_BACK); 
	livePusher.setLiveStateChangeListener(this);  
	livePusher.prepare(mSurfaceHolder);

开始推流

    livePusher.startPusher("rtmp://ip:port/hub/stream");

结束推流

    livePusher.stopPusher();

释放

    livePusher.release();

设置状态监听

	public interface LiveStateChangeListener {
	// 错误信息 非主线程调用
	public void onErrorPusher(int code);
	// 开始推流 非主线程调用
	public void onStartPusher();
	// 停止推流 非主线程调用
	public void onStopPusher();
}

获取错误信息:

   	switch (code) {
			case -100:
				Toast.makeText(MainActivity.this, "视频预览开始失败", 0).show();
				livePusher.stopPusher();
				break;
			case -101:
				Toast.makeText(MainActivity.this, "音频录制失败", 0).show();
				livePusher.stopPusher();
				break;
			case -102:
				Toast.makeText(MainActivity.this, "音频编码器配置失败", 0).show();
				livePusher.stopPusher();
				break;
			case -103:
				Toast.makeText(MainActivity.this, "视频频编码器配置失败", 0).show();
				livePusher.stopPusher();
				break;
			case -104:
				Toast.makeText(MainActivity.this, "流媒体服务器/网络等问题", 0).show();
				livePusher.stopPusher();
				break;
			}
	}

livepublisher's People

Contributors

edu-lance avatar

Watchers

James Cloos avatar zzok avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.