-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2503 from b95505017/rtmp_client
Rtmp client
- Loading branch information
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"/> |
70 changes: 70 additions & 0 deletions
70
extensions/rtmp/src/main/java/com/google/android/exoplayer2/ext/rtmp/RtmpDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |