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
private fun extractMediaSourceFromUri(uri: Uri): MediaSource { | |
val userAgent = Util.getUserAgent(this, "Exo") | |
return ExtractorMediaSource.Factory(DefaultDataSourceFactory(this, userAgent)) | |
.setExtractorsFactory(DefaultExtractorsFactory()).createMediaSource(uri) | |
} |
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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_player) | |
val mediaSource = extractMediaSourceFromUri(Uri.parse("asset:///heart_attack.mp3")) | |
val exoPlayer = ExoPlayerFactory.newSimpleInstance( | |
baseContext, DefaultRenderersFactory(baseContext) | |
, DefaultTrackSelector(), | |
DefaultLoadControl() | |
) | |
exoPlayer.apply { |
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
class MusicService : MediaBrowserServiceCompat() { | |
override fun onLoadChildren(parentId: String, result: Result<MutableList<MediaBrowserCompat.MediaItem>>) { | |
} | |
override fun onGetRoot(clientPackageName: String, clientUid: Int, rootHints: Bundle?): BrowserRoot? { | |
return BrowserRoot("", null) | |
} | |
} |
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
<service android:name=".MusicService"> | |
<intent-filter> | |
<action android:name="android.media.browse.MediaBrowserService"/> | |
</intent-filter> | |
</service> |
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
class MusicService : MediaBrowserServiceCompat() { | |
private var mMediaSession: MediaSessionCompat? = null | |
private lateinit var mStateBuilder: PlaybackStateCompat.Builder | |
private var mExoPlayer: SimpleExoPlayer? = null | |
private var oldUri: Uri? = null | |
private val mMediaSessionCallback = object : MediaSessionCompat.Callback() { | |
override fun onPlayFromUri(uri: Uri?, extras: Bundle?) { | |
super.onPlayFromUri(uri, extras) | |
uri?.let { | |
val mediaSource = extractMediaSourceFromUri(uri) |
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
class PlayerActivity : AppCompatActivity() { | |
private lateinit var mMediaBrowserCompat: MediaBrowserCompat | |
private val connectionCallback: MediaBrowserCompat.ConnectionCallback = object : MediaBrowserCompat.ConnectionCallback() { | |
override fun onConnected() { | |
// The browser connected to the session successfully, use the token to create the controller | |
super.onConnected() | |
mMediaBrowserCompat.sessionToken.also { token -> |
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
interface Displayable { | |
fun getType(): Int | |
} | |
// ---------------------------------- | |
abstract class ViewRenderer<in D : Displayable, VH : RecyclerView.ViewHolder>(val type: Int) { | |
abstract fun bindView(model: D, holder: VH) | |
abstract fun createViewHolder(parent: ViewGroup): VH | |
} |
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
// Those are two tasks. | |
// TASK 1 | |
open class SingletonHolder<out T, in A>(creator: (A) -> T) { | |
private var creator: ((A) -> T)? = creator | |
@Volatile | |
private var instance: T? = null |
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
// With the assumption, this code is written inside a view | |
// choose a reasonable range of colors, some ranges won't be drawn and I don't know why actually. | |
private val shadowStartColor = 0x99ffffff.toInt() | |
private val shadowEndColor = 0x03ffffff | |
private val shadowSize = 50f | |
val radialGradientPaint =RadialGradient(centerX | |
, centerY, | |
radius, | |
intArrayOf(shadowStartColor, shadowEndColor), | |
floatArrayOf(0f, 1f), |
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
val path = Path() | |
val paint = Paint() | |
paint.apply { | |
strokeWidth = 20f | |
style = Paint.Style.STROKE | |
} | |
path.apply { | |
moveTo(xCenter, yCenter) |
OlderNewer