commit
1279b7dcf1
34
extensions/rtmp/README.md
Normal file
34
extensions/rtmp/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# ExoPlayer RTMP Extension #
|
||||
|
||||
## Description ##
|
||||
|
||||
The RTMP Extension is an [DataSource][] implementation for playing [RTMP][] streaming using
|
||||
[Librtmp Client for Android].
|
||||
|
||||
## Using the extension ##
|
||||
|
||||
When building [MediaSource][], inject `RtmpDataSourceFactory` like this:
|
||||
|
||||
```java
|
||||
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
|
||||
int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
|
||||
: Util.inferContentType("." + overrideExtension);
|
||||
switch (type) {
|
||||
|
||||
// ... other types cases
|
||||
|
||||
case C.TYPE_OTHER:
|
||||
DataSource.Factory factory = uri.getScheme().equals("rtmp") ? new RtmpDataSourceFactory() : mediaDataSourceFactory;
|
||||
return new ExtractorMediaSource(uri, factory, new DefaultExtractorsFactory(), mainHandler, eventLogger);
|
||||
default: {
|
||||
throw new IllegalStateException("Unsupported type: " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
[DataSource]: https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/upstream/DataSource.html
|
||||
[RTMP]: https://en.wikipedia.org/wiki/Real-Time_Messaging_Protocol
|
||||
[Librtmp Client for Android]: https://github.com/ant-media/LibRtmp-Client-for-Android
|
||||
[MediaSource]: https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/source/MediaSource.html
|
29
extensions/rtmp/build.gradle
Normal file
29
extensions/rtmp/build.gradle
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2016 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion project.ext.compileSdkVersion
|
||||
buildToolsVersion project.ext.buildToolsVersion
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
targetSdkVersion project.ext.targetSdkVersion
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':library-core')
|
||||
compile 'net.butterflytv.utils:rtmp-client:0.2.6.1'
|
||||
}
|
17
extensions/rtmp/src/main/AndroidManifest.xml
Normal file
17
extensions/rtmp/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest package="com.google.android.exoplayer2.ext.rtmp"/>
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.ext.rtmp;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||
|
||||
import net.butterflytv.rtmp_client.RtmpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A Real-Time Messaging Protocol (RTMP) {@link DataSource}.
|
||||
*/
|
||||
public final class RtmpDataSource implements DataSource {
|
||||
private final RtmpClient rtmpClient;
|
||||
private Uri uri;
|
||||
|
||||
public RtmpDataSource() {
|
||||
rtmpClient = new RtmpClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long open(DataSpec dataSpec) throws IOException {
|
||||
uri = dataSpec.uri;
|
||||
int result = rtmpClient.open(dataSpec.uri.toString(), false);
|
||||
if (result < 0) {
|
||||
return 0;
|
||||
}
|
||||
return C.LENGTH_UNSET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
rtmpClient.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int offset, int readLength) throws IOException {
|
||||
return rtmpClient.read(buffer, offset, readLength);
|
||||
}
|
||||
|
||||
public final static class RtmpDataSourceFactory implements DataSource.Factory {
|
||||
@Override
|
||||
public DataSource createDataSource() {
|
||||
return new RtmpDataSource();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user