This file contains hidden or 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
| public class MyService extends Service{ | |
| @Override | |
| public int onStartCommand(Intent intent, int flags, int startId) { | |
| boolean containsCommand = MyIntentBuilder | |
| .containsCommand(intent); | |
| d(TAG, | |
| String.format( | |
| "Service in [%s] state. cmdId: [%d]. startId: [%d]", | |
| mServiceIsStarted ? "STARTED" : "NOT STARTED", | |
| containsCommand ? |
This file contains hidden or 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
| public class MyService extends Service{ | |
| private void commandStart() { | |
| if (!mServiceIsStarted) { | |
| moveToStartedState(); | |
| return; | |
| } | |
| if (mExecutor == null) { |
This file contains hidden or 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
| enum class SourceType { | |
| local_audio, local_video, http_audio, http_video, playlist; | |
| } | |
| data class PlayerState(var window: Int = 0, | |
| var position: Long = 0, | |
| var whenReady: Boolean = true, | |
| var source: SourceType = local_audio) | |
| class PlayerHolder(val context: Context, |
This file contains hidden or 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
| <com.google.android.exoplayer2.ui.PlayerView | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| android:id="@+id/exoplayerview_activity_video" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| /> |
This file contains hidden or 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
| fun stop() { | |
| player.stop(true) | |
| info { "SimpleExoPlayer is stopped" } | |
| } | |
| fun release() { | |
| player.release() | |
| info { "SimpleExoPlayer is released" } | |
| } |
This file contains hidden or 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
| class VideoActivity : AppCompatActivity() { | |
| lateinit var playerHolder: PlayerHolder | |
| val state = PlayerState() | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| ... | |
| playerHolder = PlayerHolder(this, exoplayerview_activity_video, state) | |
| } |
This file contains hidden or 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
| data class PlayerState(var window: Int = 0, | |
| var position: Long = 0, | |
| var whenReady: Boolean = true, | |
| var source: SourceType = local_audio) |
This file contains hidden or 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
| class PlayerHolder(...) : AnkoLogger { | |
| ... | |
| fun start() { | |
| // Load media. | |
| player.prepare(...) | |
| // Restore state (after onResume()/onStart()) | |
| with(playerState) { | |
| // Start playback when media has buffered enough | |
| // (whenReady is true by default). | |
| player.playWhenReady = whenReady |
This file contains hidden or 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
| // Create player | |
| player = ExoPlayerFactory.newSimpleInstance( | |
| // Renders audio, video, text (subtitles) content | |
| DefaultRenderersFactory(ctx), | |
| // Choose best audio, video, text track from available sources, | |
| // based on bandwidth, device capabilities, language, etc | |
| DefaultTrackSelector(), | |
| // Manage buffering and loading data over the network | |
| DefaultLoadControl() | |
| ).apply { ... } |
This file contains hidden or 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
| val mediaMap = mapOf<SourceType, Uri>( | |
| local_audio to Uri.parse("asset:///audio/file.mp3"), | |
| local_video to Uri.parse("asset:///video/file.mp4"), | |
| http_audio to Uri.parse("http://site...file.mp3"), | |
| http_video to Uri.parse("http://site...file.mp4") | |
| ) | |
| enum class SourceType { | |
| local_audio, local_video, http_audio, http_video, playlist; |