利用ffmpeg+nginx+Ijkplayer在自己的电脑和手机上搭建rtmp直播上(下——Android端)
2018-02-20 21:42
531 查看
之前写了一篇利用ffmpeg+nginx和笔记本电脑搭建直播推流的博客,一直忘记了写怎么在Android端进行拉流,今天刚刚来到学校,忽然想起来,就接着上一次的内容写下去了
上一次的博客是http://blog.csdn.net/qq_37656219/article/details/79330298
我们用到了开源框架Ijkplayer(哈哈因为不用商业授权,膜大佬)。Ijkplayer是非常好用的开源框架,但是要用起来其实也挺麻烦的,之前看过别人写的一些博客,都是要自己编译什么的,虽然步骤也不难,但是对于广大使用Win的人来说就有点尴尬了,所以我们这篇不用自己编译,而且亲测可行。啧啧啧。开始吧
首先要配置一下Android Studio,将build.gradle改为如下
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.drw.guannie"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {//这个是要添加的
main {
jniLibs.srcDirs = ['libs']
}
}
}
repositories {//这个也是要添加的
mavenCentral()
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
dependencies {
compile(name: 'ijkplayer-java-release', ext: 'aar')//这个也是要添加的
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
} 修改完后Rebuild project,也就是菜单栏--Build--Rebuild Project
然后呢,就要去https://github.com/Bilibili/ijkplayer,这里下载ijkplayer源码了,因为我们需要android/ijkplayer/ijkplayer-example/src/main/java/tv/danmaku/ijk/media/example/widget/media目录下的一些类,但是将这些类复制到我们的项目文件下后又是让人头大的改代码,所以这次我准备好了修改好的供大家下载将压缩文件解压后放到【项目名】/app/src/main/java下,然后就是so文件,我也为大家准备好了可以直接使用的,
http://download.csdn.net/download/qq_37656219/10253769 下载下来解压后放在【项目名】/app/libs/armeabi文件夹下(这个文件夹自己创建),然后再愉快地Rebuild一下。可以开始码代码了,首先用上一篇介绍的方法搭建推流服务器,然后记下rtmp链接。最后写代码
布局文件如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.drw.guannie.MainActivity">
<widget.media.IjkVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
主类如下public class MainActivity extends AppCompatActivity{
private String url2 = "这个写你的rtmp链接";如rtmp://10.30.24.207:80/live/demo
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IjkVideoView mVideoView = (IjkVideoView) findViewById(R.id.video_view);
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkffmpeg.so");
mVideoView.setVideoPath(url2);
mVideoView.start();
}
} 然后再写入权限 <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" /> 然后打包在真机上测试就会成功了,注意,这个不能从虚拟机测试,会报错的。
好了,就到这里了,我是菜鸟,多多指教,DRW
上一次的博客是http://blog.csdn.net/qq_37656219/article/details/79330298
我们用到了开源框架Ijkplayer(哈哈因为不用商业授权,膜大佬)。Ijkplayer是非常好用的开源框架,但是要用起来其实也挺麻烦的,之前看过别人写的一些博客,都是要自己编译什么的,虽然步骤也不难,但是对于广大使用Win的人来说就有点尴尬了,所以我们这篇不用自己编译,而且亲测可行。啧啧啧。开始吧
首先要配置一下Android Studio,将build.gradle改为如下
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.drw.guannie"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {//这个是要添加的
main {
jniLibs.srcDirs = ['libs']
}
}
}
repositories {//这个也是要添加的
mavenCentral()
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}
dependencies {
compile(name: 'ijkplayer-java-release', ext: 'aar')//这个也是要添加的
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
} 修改完后Rebuild project,也就是菜单栏--Build--Rebuild Project
然后呢,就要去https://github.com/Bilibili/ijkplayer,这里下载ijkplayer源码了,因为我们需要android/ijkplayer/ijkplayer-example/src/main/java/tv/danmaku/ijk/media/example/widget/media目录下的一些类,但是将这些类复制到我们的项目文件下后又是让人头大的改代码,所以这次我准备好了修改好的供大家下载将压缩文件解压后放到【项目名】/app/src/main/java下,然后就是so文件,我也为大家准备好了可以直接使用的,
http://download.csdn.net/download/qq_37656219/10253769 下载下来解压后放在【项目名】/app/libs/armeabi文件夹下(这个文件夹自己创建),然后再愉快地Rebuild一下。可以开始码代码了,首先用上一篇介绍的方法搭建推流服务器,然后记下rtmp链接。最后写代码
布局文件如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.drw.guannie.MainActivity">
<widget.media.IjkVideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
主类如下public class MainActivity extends AppCompatActivity{
private String url2 = "这个写你的rtmp链接";如rtmp://10.30.24.207:80/live/demo
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IjkVideoView mVideoView = (IjkVideoView) findViewById(R.id.video_view);
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkffmpeg.so");
mVideoView.setVideoPath(url2);
mVideoView.start();
}
} 然后再写入权限 <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" /> 然后打包在真机上测试就会成功了,注意,这个不能从虚拟机测试,会报错的。
好了,就到这里了,我是菜鸟,多多指教,DRW
相关文章推荐
- Android学习——利用ffmpeg+nginx+Ijkplayer在自己的电脑和手机上搭建rtmp直播上
- iOS开发之利用IJKPlayer+nginx+rtmp搭建直播的推流和拉流
- 在自己的电脑下搭建nginx+rtmp的流媒体服务器及用java对推流权限验证
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- 利用nginx搭建RTMP视频点播、直播、HLS服务器(转)
- 新 CentOS 6.5 6.9 环境下搭建直播模拟测试环境 ffmpeg+nginx=rtmp (傻瓜式环境搭建)
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- mac下利用ffmpeg+nginx搭建直播服务器的总结
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- Android中直播视频技术探究之---视频直播服务端环境搭建(Nginx+RTMP)
- nginx开发(四)调用ffmpeg,搭建rtmp直播流。
- 直播系列5-使用nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器笔记(二)
- 一步步搭建视频直播系统,基于LFLiveKit+ijkplayer+rtmp(iOS端)
- Android中直播视频技术探究之---视频直播服务端环境搭建(Nginx+RTMP)
- Android中直播视频技术探究之---视频直播服务端环境搭建(Nginx+RTMP)
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- 使用nginx在android手机上搭建rtmp服务器并测试