Skip to content

Commit

Permalink
code fixes - fix trailer video player show black screen when playing …
Browse files Browse the repository at this point in the history
…video
  • Loading branch information
ifechukwu committed Apr 7, 2022
1 parent dccfbd9 commit 5e33585
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 87 deletions.
21 changes: 15 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ plugins {
id "androidx.navigation.safeargs"
id "dagger.hilt.android.plugin"
}
// Creates a variable called keystorePropertiesFile, and initializes it to the
// keystore.properties file.
def localPropertiesFile = rootProject.file("local.properties")

// Initializes a new Properties() object called localProperties.
def localProperties = new Properties()

// Loads the local.properties file into the localProperties object.
localProperties.load(new FileInputStream(localPropertiesFile))

android {
compileSdkVersion 31
Expand All @@ -15,18 +24,18 @@ android {
applicationId "com.henryudorji.theater"
minSdkVersion 21
targetSdkVersion 31
versionCode 2
versionName "1.1"
versionCode 3
versionName "1.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
storeFile file("C:/Users/ifechukwu.udorji/WorkFolder/Personal/Android/Theater/HashConceptsKey.jks")
storePassword "@Henry1998"
keyAlias "HashConceptsKey"
keyPassword "@Henry1998"
storeFile file(localProperties['SIGNING_JKS_FILE_PATH'])
storePassword localProperties['SIGNING_KEYSTORE_PASSWORD']
keyAlias localProperties['SIGNING_KEY_ALIAS']
keyPassword localProperties['SIGNING_KEY_PASSWORD']
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class MovieDetailResponse(
@SerializedName("backdrop_path")
val backdropPath: String,
@SerializedName("budget")
val budget: Int,
val budget: Int?,
@SerializedName("genres")
val genres: List<Genre>,
@SerializedName("id")
Expand All @@ -25,9 +25,9 @@ data class MovieDetailResponse(
@SerializedName("release_date")
val releaseDate: String,
@SerializedName("revenue")
val revenue: Int,
val revenue: Int?,
@SerializedName("runtime")
val runtime: Int,
val runtime: Int?,
@SerializedName("title")
val title: String,
@SerializedName("video")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ data class TvSeriesDetailResponse(
@SerializedName("name")
val name: String,
@SerializedName("episode_runtime")
val episodeRunTime: String,
val episodeRunTime: String?,
@SerializedName("number_of_episodes")
val numberOfEpisodes: Int,
val numberOfEpisodes: Int?,
@SerializedName("number_of_seasons")
val numberOfSeasons: Int,
val numberOfSeasons: Int?,
@SerializedName("original_name")
val originalName: String,
@SerializedName("overview")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,28 @@ class MovieDetailFragment: BaseFragment<FragmentMovieDetailBinding, DetailsViewM
}

private fun showInitialDetail(movieData: MovieDetailResponse?, tvData: TvSeriesDetailResponse?) {
val genreList: List<Genre>
var genreList: List<Genre> = mutableListOf()
if (movieData == null) {
Picasso.get().load(BASE_URL_IMAGE + tvData?.posterPath).into(binding.barImage)
binding.movieTitle.text = tvData?.name
binding.ratingText.text = tvData?.voteAverage.toString()
binding.runtimeText.text = "${tvData?.episodeRunTime.toString()} minutes"
genreList = tvData?.genres!!
binding.movieOverviewText.text = tvData.overview
binding.budgetText.text = "Seasons: ${tvData.numberOfSeasons}"
binding.revenueText.text = "Episodes: ${tvData.numberOfEpisodes}"
}else {
tvData?.let {
binding.movieTitle.text = it.name
binding.ratingText.text = it.voteAverage.toString()
binding.runtimeText.text = "${it.episodeRunTime ?: "..."} minutes"
genreList = it.genres
binding.movieOverviewText.text = it.overview
binding.budgetText.text = "Seasons: ${it.numberOfSeasons ?: "..."}"
binding.revenueText.text = "Episodes: ${it.numberOfEpisodes ?: "..."}"
}
} else {
Picasso.get().load(BASE_URL_IMAGE + movieData.posterPath).into(binding.barImage)
binding.movieTitle.text = movieData.title
binding.ratingText.text = movieData.voteAverage.toString()
binding.runtimeText.text = "${movieData.runtime} minutes"
binding.runtimeText.text = "${movieData.runtime ?: "..."} minutes"
genreList = movieData.genres
binding.movieOverviewText.text = movieData.overview

val budget = AppUtils.coolNumberFormat(movieData.budget.toLong())
val revenue = AppUtils.coolNumberFormat(movieData.revenue.toLong())
val budget = AppUtils.coolNumberFormat(movieData.budget?.toLong())
val revenue = AppUtils.coolNumberFormat(movieData.revenue?.toLong())
binding.budgetText.text = "Budget: $$budget"
binding.revenueText.text = "Revenue: $$revenue"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ import kotlinx.coroutines.launch

class TrailerVideoRvAdapter(val lifecycle: Lifecycle) : RecyclerView.Adapter<TrailerVideoRvAdapter.TrailerVideoViewHolder>() {

inner class TrailerVideoViewHolder(val binding: RvTrailerLayoutBinding): RecyclerView.ViewHolder(binding.root)
inner class TrailerVideoViewHolder(val binding: RvTrailerLayoutBinding): RecyclerView.ViewHolder(binding.root) {
fun bind(video: Video?) {
video?.let {
//Play video of movie or series
binding.youtubePlayerView.addYouTubePlayerListener(object : AbstractYouTubePlayerListener() {
override fun onReady(youTubePlayer: YouTubePlayer) {
val videoId = it.key
youTubePlayer.cueVideo(videoId, 0f)
}
})
}
}
}

private val differCallback = object: DiffUtil.ItemCallback<Video>() {
override fun areItemsTheSame(oldItem: Video, newItem: Video): Boolean {
Expand All @@ -36,24 +48,14 @@ class TrailerVideoRvAdapter(val lifecycle: Lifecycle) : RecyclerView.Adapter<Tra
parent,
false
)
lifecycle.addObserver(binding.youtubePlayerView)
return TrailerVideoViewHolder(binding)
}

override fun onBindViewHolder(holder: TrailerVideoViewHolder, position: Int) {
val video = differ.currentList[position]

holder.binding.apply {
//Play video of movie or series
CoroutineScope(Dispatchers.Main).launch {
lifecycle.addObserver(youtubePlayerView)
youtubePlayerView.addYouTubePlayerListener(object : AbstractYouTubePlayerListener() {
override fun onReady(youTubePlayer: YouTubePlayer) {
val videoId = video.key
youTubePlayer.cueVideo(videoId, 0f)
}
})
}
}
holder.bind(video)
}

override fun getItemCount(): Int {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/henryudorji/theater/utils/AppUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import kotlin.math.pow

object AppUtils {

fun coolNumberFormat(count: Long): String {
fun coolNumberFormat(count: Long?): String {
if (count == null) return "..."
if (count < 1000) return "" + count
val exp = (ln(count.toDouble()) / ln(1000.0)).toInt()
val format = DecimalFormat("0.#")
Expand Down
48 changes: 14 additions & 34 deletions app/src/main/res/layout/fragment_movie_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,55 +69,35 @@
app:layout_constraintEnd_toEndOf="parent"
/>

<ImageView
android:id="@+id/ratingImage"
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:src="@drawable/ic_star"
android:layout_marginTop="@dimen/_5sdp"
android:layout_marginStart="@dimen/_10sdp"
app:layout_constraintTop_toBottomOf="@id/movieTitle"
app:layout_constraintStart_toStartOf="parent"
/>

<TextView
android:id="@+id/ratingText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_2sdp"
android:fontFamily="@font/raleway_regular"
android:text=""
android:textSize="@dimen/_11ssp"
android:textColor="@color/gray"
app:layout_constraintStart_toEndOf="@id/ratingImage"
app:layout_constraintTop_toTopOf="@id/ratingImage"
app:layout_constraintBottom_toBottomOf="@id/ratingImage"
/>

<ImageView
android:id="@+id/timeImage"
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:src="@drawable/ic_time"
android:layout_marginStart="@dimen/_20sdp"
app:layout_constraintStart_toEndOf="@id/ratingText"
app:layout_constraintTop_toTopOf="@id/ratingText"
app:layout_constraintBottom_toBottomOf="@id/ratingText"
/>
android:layout_marginTop="@dimen/_5sdp"
android:layout_marginStart="@dimen/_10sdp"
android:drawablePadding="@dimen/_5sdp"
app:layout_constraintTop_toBottomOf="@id/movieTitle"
app:layout_constraintStart_toStartOf="parent"
app:drawableStartCompat="@drawable/ic_star" />

<TextView
android:id="@+id/runtime_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/raleway_regular"
android:text=""
android:layout_marginStart="@dimen/_2sdp"
android:textSize="@dimen/_11ssp"
android:textColor="@color/gray"
app:layout_constraintStart_toEndOf="@id/timeImage"
app:layout_constraintTop_toTopOf="@id/timeImage"
app:layout_constraintBottom_toBottomOf="@id/timeImage"
/>
android:layout_marginStart="@dimen/_20sdp"
android:drawablePadding="@dimen/_5sdp"
app:layout_constraintStart_toEndOf="@id/ratingText"
app:layout_constraintTop_toTopOf="@id/ratingText"
app:layout_constraintBottom_toBottomOf="@id/ratingText"
app:drawableStartCompat="@drawable/ic_time" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/genreRv"
Expand All @@ -141,7 +121,7 @@
android:textColor="@color/gray"
android:layout_marginStart="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
app:layout_constraintTop_toBottomOf="@id/ratingImage"
app:layout_constraintTop_toBottomOf="@id/ratingText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/revenueText"
/>
Expand All @@ -156,7 +136,7 @@
android:textColor="@color/gray"
android:layout_marginEnd="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
app:layout_constraintTop_toBottomOf="@id/ratingImage"
app:layout_constraintTop_toBottomOf="@id/ratingText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/budgetText"
/>
Expand Down
20 changes: 5 additions & 15 deletions app/src/main/res/layout/rv_trailer_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<io.github.florent37.shapeofview.shapes.RoundRectView
android:id="@+id/roundRectView"
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtubePlayerView"
android:layout_width="match_parent"
android:layout_height="@dimen/_150sdp"
app:shape_roundRect_topLeftRadius="@dimen/_10sdp"
app:shape_roundRect_topRightRadius="@dimen/_10sdp"
app:shape_roundRect_bottomRightRadius="@dimen/_10sdp"
app:shape_roundRect_bottomLeftRadius="@dimen/_10sdp"
app:autoPlay="false"
app:showFullScreenButton="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtubePlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:autoPlay="false"
app:showFullScreenButton="false" />
</io.github.florent37.shapeofview.shapes.RoundRectView>
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 5e33585

Please sign in to comment.