Skip to content

Commit

Permalink
modify some kotlin variables
Browse files Browse the repository at this point in the history
  • Loading branch information
weiancheng committed Jan 17, 2018
1 parent f7761f2 commit c4ea967
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MainActivity:AppCompatActivity() {
private val permissionsStorage: Array<String> = arrayOf(WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE)
private val permissionsRequestCode = 1

var listener = ExoPlayerEventListener.PlayerEventListener {
private var listener = ExoPlayerEventListener.PlayerEventListener {
onDurationChanged = { duration ->
Log.i("MainActivity", "onDurationChanged: $duration")
}
Expand All @@ -48,25 +48,25 @@ class MainActivity:AppCompatActivity() {

player.setEventListener(listener)

var play = findViewById<Button>(R.id.btn_play) as Button
val play = findViewById<Button>(R.id.btn_play) as Button
play.setOnClickListener { view ->
player.play(url)
}

var stop = findViewById<Button>(R.id.btn_stop) as Button
val stop = findViewById<Button>(R.id.btn_stop) as Button
stop.setOnClickListener { view ->
player.stop()
}

var next = findViewById<Button>(R.id.btn_next) as Button
val next = findViewById<Button>(R.id.btn_next) as Button
next.setOnClickListener { view ->
if (player.getPlayerState() == MusicPlayerState.Play) {
player.stop()
}
player.play(local)
}

var previous = findViewById<Button>(R.id.btn_prev) as Button
val previous = findViewById<Button>(R.id.btn_prev) as Button
previous.setOnClickListener { view ->
if (player.getPlayerState() == MusicPlayerState.Play) {
player.stop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.ExoPlayerFactory
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.Player.STATE_BUFFERING
import com.google.android.exoplayer2.Player.STATE_ENDED
import com.google.android.exoplayer2.Player.STATE_IDLE
import com.google.android.exoplayer2.Player.STATE_READY
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.Timeline
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
Expand All @@ -34,21 +31,16 @@ import weian.cheng.mediaplayerwithexoplayer.MusicPlayerState.Play
*
*/

class ExoPlayerWrapper(context: Context): IMusicPlayer {
class ExoPlayerWrapper(private val context: Context): IMusicPlayer {

private val TAG = "ExoPlayerWrapper"
private var context: Context
private val tag = "ExoPlayerWrapper"
private lateinit var exoPlayer: SimpleExoPlayer
private var isPlaying = false
private lateinit var timer: PausableTimer
private var playerState = Standby

private var listener: PlayerEventListener ?= null

init {
this.context = context
}

override fun play(uri: String) {
if (playerState == Play) {
// TODO: find out a appropriate exception or make one.
Expand Down Expand Up @@ -131,7 +123,7 @@ class ExoPlayerWrapper(context: Context): IMusicPlayer {
}

private fun initExoPlayer(url: String) {
Log.i(TAG, "initExoPlayer")
Log.i(tag, "initExoPlayer")
val meter = DefaultBandwidthMeter()
val dataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "LocalExoPlayer"), meter)
val uri = Uri.parse(url)
Expand All @@ -143,16 +135,8 @@ class ExoPlayerWrapper(context: Context): IMusicPlayer {
exoPlayer.prepare(extractorMediaSource)
}

private class LocalPlayerEventListener(player: ExoPlayerWrapper,
exoplayer: ExoPlayer): Player.EventListener {

private var exoPlayer: ExoPlayer
private var musicPlayer: ExoPlayerWrapper

init {
exoPlayer = exoplayer
musicPlayer = player
}
private class LocalPlayerEventListener(private val musicPlayer: ExoPlayerWrapper,
private val exoPlayer: ExoPlayer): Player.EventListener {

override fun onPlaybackParametersChanged(playbackParameters: PlaybackParameters?) {
}
Expand Down

0 comments on commit c4ea967

Please sign in to comment.