I integrated the code from this repo into my app: https://github.com/kardelencanoglu/ExoPlayerRTSP And I'm able to see the compile, and see the player on my android app in the emulator.
On my local machine I generate a rtsp stream this way, that I can recover from VLC:
/Applications/VLC.app/Contents/MacOS/VLC -I dummy blabla.mp4 --sout '#rtp{sdp=rtsp://0.0.0.0:8082/live}' --no-sout-all --sout-keep
in my app build.gradle:
implementation 'com.google.android.exoplayer:exoplayer:2.19.1'
Included:
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
in my main activity I have:
private SimpleExoPlayer player;
private PlayerView playerView;
....
playerView = findViewById(R.id.player_view);
try {
// Overriding rtspStreamUrl for testing purposes
rtspStreamUrl = "rtsp://10.0.2.2:8082/live";
Uri videoUri = Uri.parse(rtspStreamUrl);
player = new SimpleExoPlayer.Builder(this).build();
playerView.setPlayer(player);
MediaSource mediaSource = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(this, "exoplayer-codelab")).createMediaSource(MediaItem.fromUri(videoUri));
player.prepare(mediaSource);
player.setPlayWhenReady(true);
playerView.bringToFront();
}
catch (Exception e) {
Log.e("Unable to start EXO player","");
}
I get the following error in logcat:
Playback error c*om.google.android.exoplayer2.ExoPlaybackException: Source error at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:684) at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:656) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: java.net.MalformedURLException: unknown protocol: rtsp at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:388) at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:269) at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:90) at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1013) at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:420) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) Caused by: java.net.MalformedURLException: unknown protocol: rtsp at java.net.URL.(URL.java:608) at java.net.URL.(URL.java:498) at java.net.URL.(URL.java:447) at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:530) at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:382) at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:269) at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:90) at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1013) at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:420) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012) *
Any idea would be much appreciated, thanks in advance!
I tried to retrieve the stream in VLC, it works all fine, but not in emulator.
EDIT: the problem changes if I do:
import com.google.android.exoplayer2.source.rtsp.RtspMediaSource;
and instead of Progressive I use:
MediaSource mediaSource =
new RtspMediaSource.Factory().createMediaSource(MediaItem.fromUri(rtspStreamUrl));
then I get: Playback error com.google.android.exoplayer2.ExoPlaybackException: Source error at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:684) at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:660) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: com.google.android.exoplayer2.source.rtsp.RtspMediaSource$RtspPlaybackException: SETUP 461