Skip to content

Commit

Permalink
showing notification with metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocalazansjr committed Nov 4, 2018
1 parent f3dfeff commit ceaffaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class NotificationHelper {
}

@JvmStatic
fun showPlaybackNotification(playbackState: PlaybackStateCompat, context: Context, mediaSessionCompat: MediaSessionCompat) {
fun showPlaybackNotification(playbackState: PlaybackStateCompat,
context: Context,
mediaSessionCompat: MediaSessionCompat,
artist: String?,
trackName: String?) {
val icon: Int
val playPause: String

Expand Down Expand Up @@ -72,8 +76,8 @@ class NotificationHelper {
.setShowActionsInCompactView(0, 1)

val notification = NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ID)
.setContentTitle(context.getString(R.string.notification_title))
.setContentText(context.getString(R.string.notification_text))
.setContentTitle(artist?: context.getString(R.string.notification_title))
.setContentText(trackName?: context.getString(R.string.notification_text))
.setContentIntent(contentPendingIntent)
.setSmallIcon(R.drawable.ic_notification)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.media.session.MediaSessionCompat
import android.support.v4.media.session.PlaybackStateCompat
import android.util.Log
import android.widget.Toast
import androidx.media.session.MediaButtonReceiver
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame
import com.google.android.exoplayer2.source.ExtractorMediaSource
import com.google.android.exoplayer2.source.TrackGroupArray
import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
Expand Down Expand Up @@ -70,9 +68,11 @@ class PlayerActivity : AppCompatActivity(), ExoPlayer.EventListener {
mExoPlayer!!.playWhenReady = true

mExoPlayer!!.setMetadataOutput {
Log.d(this.javaClass.name, (it.get(0) as TextInformationFrame).value)
Log.d(this.javaClass.name, (it.get(2) as TextInformationFrame).value)
it.describeContents()
NotificationHelper.showPlaybackNotification(mPlaybackState!!.build(),
this,
mMediaSession,
(it.get(0) as TextInformationFrame).value,
(it.get(2) as TextInformationFrame).value)
}
}
}
Expand Down Expand Up @@ -109,7 +109,7 @@ class PlayerActivity : AppCompatActivity(), ExoPlayer.EventListener {
)
}
PlayerActivity.mMediaSession.setPlaybackState(mPlaybackState!!.build())
NotificationHelper.showPlaybackNotification(mPlaybackState!!.build(), this, mMediaSession)
NotificationHelper.showPlaybackNotification(mPlaybackState!!.build(), this, mMediaSession, null, null)
}

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

0 comments on commit ceaffaf

Please sign in to comment.