Created
August 9, 2017 20:08
-
-
Save ponnamkarthik/c00b8d50b79ce5055b72f30af5210b4b to your computer and use it in GitHub Desktop.
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
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; | |
/** | |
* Created by faraklit on 08.01.2016. | |
*/ | |
public class RtmpDataSource implements DataSource { | |
public static class RtmpDataSourceFactory implements DataSource.Factory { | |
@Override | |
public DataSource createDataSource() { | |
return new RtmpDataSource(); | |
} | |
} | |
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 { | |
String uriString = dataSpec.uri.toString(); | |
try { | |
rtmpClient.open(uriString, false); | |
uri = dataSpec.uri; | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment