Commit ee5dbb91 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added ExoPlayer impl

working source via rtmp
still can't handle hsl
parent e2bbafb7
...@@ -17,7 +17,7 @@ android { ...@@ -17,7 +17,7 @@ android {
defaultConfig { defaultConfig {
applicationId $APPLICATION_ID applicationId $APPLICATION_ID
ndk { ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a' abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86'
} }
minSdkVersion minSdkVersion_RoomPark minSdkVersion minSdkVersion_RoomPark
targetSdkVersion targetSdkVersion_RoomPark targetSdkVersion targetSdkVersion_RoomPark
...@@ -147,6 +147,12 @@ dependencies { ...@@ -147,6 +147,12 @@ dependencies {
implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
//Exo Player
implementation "com.google.android.exoplayer:exoplayer:$exoPlayerVersion"
implementation "com.google.android.exoplayer:exoplayer-core:$exoPlayerVersion"
implementation "com.google.android.exoplayer:exoplayer-hls:$exoPlayerVersion"
implementation "com.google.android.exoplayer:extension-rtmp:$exoPlayerVersion"
//Tests //Tests
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
......
package com.biganto.visual.roompark.presentation.screen.web_cam package com.biganto.visual.roompark.presentation.screen.web_cam
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import butterknife.BindView
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.IBottomNavigation import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.google.android.exoplayer2.ExoPlayerFactory
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.ext.rtmp.RtmpDataSourceFactory
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.hls.DefaultHlsDataSourceFactory
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.ui.PlayerView
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
*/ */
...@@ -26,6 +42,11 @@ class WebCamScreenController : ...@@ -26,6 +42,11 @@ class WebCamScreenController :
constructor(id: Int) : super(bundleOf(SELECTED_CAM_INDEX_KEY to id)) constructor(id: Int) : super(bundleOf(SELECTED_CAM_INDEX_KEY to id))
@BindView(R.id.webCamPlayerView)
lateinit var playerView:PlayerView
lateinit var player:SimpleExoPlayer
override fun onViewBound(v: View) { override fun onViewBound(v: View) {
toolBar.hideAll() toolBar.hideAll()
...@@ -80,10 +101,104 @@ class WebCamScreenController : ...@@ -80,10 +101,104 @@ class WebCamScreenController :
private fun render(viewState: WebCamScreenViewState.WebCamsLIstLoaded){ private fun render(viewState: WebCamScreenViewState.WebCamsLIstLoaded){
val bandwidthMeter = DefaultBandwidthMeter.Builder(activity).build()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory()
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
player = ExoPlayerFactory.newSimpleInstance(activity!!,
trackSelector
)
// player.addListener(object : Player.EventListener {
//
// override fun onTimelineChanged(timeline: Timeline?, manifest: Any?, reason: Int) {
// Timber.d("onTimelineChanged: ");
// }
//
// override fun onTracksChanged(
// trackGroups: TrackGroupArray?,
// trackSelections: TrackSelectionArray?
// ) {
// Timber.d("onTracksChanged: ");
// }
//
// override fun onLoadingChanged(isLoading: Boolean) {
// Timber.d("onLoadingChanged: ");
// }
//
// override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
// Timber.d("onPlayerStateChanged: $playWhenReady");
// Timber.d("onPlayerStateChanged: $playbackState")
// Timber.d("onPlayerStateChanged: ${player.isPlaying}")
//
//
// }
//
// override fun onRepeatModeChanged(repeatMode: Int) {
// Timber.d("onRepeatModeChanged: ");
// }
//
// override fun onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean) {
// Timber.d("onShuffleModeEnabledChanged");
// }
//
// override fun onPlayerError(error: ExoPlaybackException?) {
// Timber.d("onPlayerError")
// }
//
// override fun onPositionDiscontinuity(reason: Int) {
// Timber.d("onPositionDiscontinuity")
// }
//
// override fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters?) {
// Timber.d("onPlaybackParametersChanged")
// }
//
// override fun onPlaybackSuppressionReasonChanged(playbackSuppressionReason: Int) {
// Timber.d("onPlaybackSuppressionReasonChanged")
// }
//
// override fun onIsPlayingChanged(isPlaying: Boolean) {
// Timber.d("onIsPlayingChanged")
// }
//
// })
playerView.player = player
val sourceUrl = viewState.camList.first{it.index == viewState.selectedCamIndex}.streams
.first().hls
var rtmpUrl = viewState.camList.first{it.index == viewState.selectedCamIndex}.streams
.first().rtmp
// rtmpUrl = "rtmp://room-park.ru:1935/cam2-360/stream"
// Timber.d("source url : ${Uri.parse(rtmpUrl)}")
// val mediaSource = buildMediaSource(Uri.parse(sourceUrl))
val mediaSource = buildRtmps(Uri.parse(rtmpUrl))
Timber.d("source url : ${Uri.parse(sourceUrl)}")
Timber.d("mediaSource : $mediaSource")
player.prepare(mediaSource,true,true)
player.playWhenReady = true
Timber.d(" after all: ${player.playbackState}")
// player.seekToDefaultPosition()
} }
override fun getLayoutId(): Int = R.layout.webcam_screen override fun getLayoutId(): Int = R.layout.webcam_screen
private fun buildMediaSource(uri: Uri): MediaSource {
val source = DefaultDataSourceFactory(activity,"ua")
val dataSourceFactory = DefaultHlsDataSourceFactory(source)//.createDataSource(DATA_TYPE_DRM)
return HlsMediaSource.Factory(dataSourceFactory)
.setAllowChunklessPreparation(true)
.createMediaSource(uri)
}
private fun buildRtmps(uri: Uri): MediaSource {
val source = DefaultDataSourceFactory(activity,"ua")
val dataSourceFactory = RtmpDataSourceFactory()
return ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri)
}
} }
\ No newline at end of file
...@@ -11,7 +11,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString ...@@ -11,7 +11,7 @@ import com.biganto.visual.roompark.util.monades.ExceptionString
sealed class WebCamScreenViewState : BigantoBaseViewState() { sealed class WebCamScreenViewState : BigantoBaseViewState() {
class Idle : WebCamScreenViewState() class Idle : WebCamScreenViewState()
class WebCamsLIstLoaded(camList:List<WebCamModel>,selectedCamIndex:Int) : WebCamScreenViewState() class WebCamsLIstLoaded(val camList:List<WebCamModel>,val selectedCamIndex:Int) : WebCamScreenViewState()
class CamSelected(model:WebCamModel) : WebCamScreenViewState() class CamSelected(val model:WebCamModel) : WebCamScreenViewState()
class SomeError(val exception: ExceptionString) : WebCamScreenViewState() class SomeError(val exception: ExceptionString) : WebCamScreenViewState()
} }
\ No newline at end of file
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<VideoView <com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/webCamPlayerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
......
...@@ -23,4 +23,5 @@ ext { ...@@ -23,4 +23,5 @@ ext {
butterKnifeVersion = '10.2.0' butterKnifeVersion = '10.2.0'
daggerVersion = '2.25.2' daggerVersion = '2.25.2'
rxRelayVersion = '2.1.1' rxRelayVersion = '2.1.1'
exoPlayerVersion = "2.10.8"
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment