Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for newer video_player vesions #1146

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group 'com.jhomlala.better_player.better_player'
version '1.0-SNAPSHOT'

buildscript {
ext.exoPlayerVersion = "2.17.1"
ext.exoPlayerVersion = "2.18.2"
ext.lifecycleVersion = "2.4.0-beta01"
ext.annotationVersion = "1.2.0"
ext.workVersion = "2.7.0"
Expand Down
69 changes: 36 additions & 33 deletions android/src/main/kotlin/com/jhomlala/better_player/BetterPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
Expand Down Expand Up @@ -32,7 +31,6 @@ import com.google.android.exoplayer2.drm.FrameworkMediaDrm
import com.google.android.exoplayer2.drm.UnsupportedDrmException
import com.google.android.exoplayer2.drm.DummyExoMediaDrm
import com.google.android.exoplayer2.drm.LocalMediaDrmCallback
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.ClippingMediaSource
import com.google.android.exoplayer2.ui.PlayerNotificationManager.MediaDescriptionAdapter
Expand All @@ -51,14 +49,12 @@ import com.google.android.exoplayer2.source.hls.HlsMediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import io.flutter.plugin.common.EventChannel.EventSink
import androidx.media.session.MediaButtonReceiver
import androidx.work.Data
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.drm.DrmSessionManagerProvider
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride
import com.google.android.exoplayer2.trackselection.TrackSelectionOverrides
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride
import com.google.android.exoplayer2.upstream.DataSource
import com.google.android.exoplayer2.upstream.DefaultDataSource
import com.google.android.exoplayer2.util.Util
Expand Down Expand Up @@ -383,17 +379,13 @@ internal class BetterPlayer(
): MediaSource {
val type: Int
if (formatHint == null) {
var lastPathSegment = uri.lastPathSegment
if (lastPathSegment == null) {
lastPathSegment = ""
}
type = Util.inferContentType(lastPathSegment)
type = Util.inferContentType(uri)
} else {
type = when (formatHint) {
FORMAT_SS -> C.TYPE_SS
FORMAT_DASH -> C.TYPE_DASH
FORMAT_HLS -> C.TYPE_HLS
FORMAT_OTHER -> C.TYPE_OTHER
FORMAT_SS -> C.CONTENT_TYPE_SS
FORMAT_DASH -> C.CONTENT_TYPE_DASH
FORMAT_HLS -> C.CONTENT_TYPE_HLS
FORMAT_OTHER -> C.CONTENT_TYPE_OTHER
else -> -1
}
}
Expand All @@ -408,26 +400,42 @@ internal class BetterPlayer(
drmSessionManagerProvider = DrmSessionManagerProvider { drmSessionManager }
}
return when (type) {
C.TYPE_SS -> SsMediaSource.Factory(
C.CONTENT_TYPE_SS -> SsMediaSource.Factory(
DefaultSsChunkSource.Factory(mediaDataSourceFactory),
DefaultDataSource.Factory(context, mediaDataSourceFactory)
)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
.apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}
.createMediaSource(mediaItem)
C.TYPE_DASH -> DashMediaSource.Factory(
C.CONTENT_TYPE_DASH -> DashMediaSource.Factory(
DefaultDashChunkSource.Factory(mediaDataSourceFactory),
DefaultDataSource.Factory(context, mediaDataSourceFactory)
)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
.apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}
.createMediaSource(mediaItem)
C.TYPE_HLS -> HlsMediaSource.Factory(mediaDataSourceFactory)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
C.CONTENT_TYPE_HLS -> HlsMediaSource.Factory(mediaDataSourceFactory)
.apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}
.createMediaSource(mediaItem)
C.TYPE_OTHER -> ProgressiveMediaSource.Factory(
C.CONTENT_TYPE_OTHER -> ProgressiveMediaSource.Factory(
mediaDataSourceFactory,
DefaultExtractorsFactory()
)
.setDrmSessionManagerProvider(drmSessionManagerProvider)
.apply {
if (drmSessionManagerProvider != null) {
setDrmSessionManagerProvider(drmSessionManagerProvider!!)
}
}
.createMediaSource(mediaItem)
else -> {
throw IllegalStateException("Unsupported type: $type")
Expand Down Expand Up @@ -508,12 +516,12 @@ internal class BetterPlayer(
val audioComponent = exoPlayer?.audioComponent ?: return
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
audioComponent.setAudioAttributes(
AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(),
AudioAttributes.Builder().setContentType(C.AUDIO_CONTENT_TYPE_MOVIE).build(),
!mixWithOthers
)
} else {
audioComponent.setAudioAttributes(
AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build(),
AudioAttributes.Builder().setContentType(C.AUDIO_CONTENT_TYPE_MUSIC).build(),
!mixWithOthers
)
}
Expand Down Expand Up @@ -707,17 +715,12 @@ internal class BetterPlayer(
if (mappedTrackInfo != null) {
val builder = trackSelector.parameters.buildUpon()
.setRendererDisabled(rendererIndex, false)
.setTrackSelectionOverrides(
TrackSelectionOverrides.Builder().addOverride(
TrackSelectionOverrides.TrackSelectionOverride(
mappedTrackInfo.getTrackGroups(
rendererIndex
).get(groupIndex)
)
).build()
.addOverride(TrackSelectionOverride(mappedTrackInfo.getTrackGroups(rendererIndex)
.get(groupIndex), rendererIndex)
)
.build()

trackSelector.setParameters(builder)
trackSelector.parameters = builder
}
}

Expand Down
9 changes: 4 additions & 5 deletions ios/Classes/BetterPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,7 @@ - (void)setSpeed:(double)speed result:(FlutterResult)result {
result([FlutterError errorWithCode:@"unsupported_speed"
message:@"Speed must be >= 0.0 and <= 2.0"
details:nil]);
} else if ((speed > 1.0 && _player.currentItem.canPlayFastForward) ||
(speed < 1.0 && _player.currentItem.canPlaySlowForward)) {
_playerRate = speed;
result(nil);
} else {
} else if ((speed > 1.0) || (speed < 1.0)) { _playerRate = speed; result(nil); } else {
if (speed > 1.0) {
result([FlutterError errorWithCode:@"unsupported_fast_forward"
message:@"This video cannot be played fast forward"
Expand All @@ -568,6 +564,9 @@ - (void)setSpeed:(double)speed result:(FlutterResult)result {
}

if (_isPlaying){
if (@available(iOS 16, *)) {
_player.defaultRate = speed;
}
_player.rate = _playerRate;
}
}
Expand Down
15 changes: 4 additions & 11 deletions lib/src/configuration/better_player_controls_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class BetterPlayerControlsConfiguration {
final Duration controlsHideTime;

///Parameter used to build custom controls
final Widget Function(BetterPlayerController controller,
Function(bool) onPlayerVisibilityChanged)? customControlsBuilder;
final Widget Function(BetterPlayerController controller, Function(bool) onPlayerVisibilityChanged)? customControlsBuilder;

///Parameter used to change theme of the player
final BetterPlayerTheme? playerTheme;
Expand Down Expand Up @@ -217,13 +216,7 @@ class BetterPlayerControlsConfiguration {

factory BetterPlayerControlsConfiguration.white() {
return const BetterPlayerControlsConfiguration(
controlBarColor: Colors.white,
textColor: Colors.black,
iconsColor: Colors.black,
progressBarPlayedColor: Colors.black,
progressBarHandleColor: Colors.black,
progressBarBufferedColor: Colors.black54,
progressBarBackgroundColor: Colors.white70);
controlBarColor: Colors.white, textColor: Colors.black, iconsColor: Colors.black, progressBarPlayedColor: Colors.black, progressBarHandleColor: Colors.black, progressBarBufferedColor: Colors.black54, progressBarBackgroundColor: Colors.white70);
}

factory BetterPlayerControlsConfiguration.cupertino() {
Expand All @@ -240,8 +233,8 @@ class BetterPlayerControlsConfiguration {
///Setup BetterPlayerControlsConfiguration based on Theme options.
factory BetterPlayerControlsConfiguration.theme(ThemeData theme) {
return BetterPlayerControlsConfiguration(
textColor: theme.textTheme.bodyText1?.color ?? Colors.white,
iconsColor: theme.textTheme.button?.color ?? Colors.white,
textColor: theme.textTheme.bodyMedium?.color ?? Colors.white,
iconsColor: theme.textTheme.bodyMedium?.color ?? Colors.white,
);
}
}
Loading