Skip to content

Commit

Permalink
Fix set is video
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Jan 3, 2024
1 parent 6631879 commit e6bb865
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 105 deletions.
70 changes: 17 additions & 53 deletions lib/src/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class PlayerService {
StreamSubscription<Duration>? _positionSub;
StreamSubscription<bool>? _isCompletedSub;
StreamSubscription<double>? _volumeSub;
StreamSubscription<Tracks>? _tracksSub;

final _queueController = StreamController<bool>.broadcast();
Stream<bool> get queueChanged => _queueController.stream;
Expand Down Expand Up @@ -67,27 +68,15 @@ class PlayerService {
if (value == null || value == _audio) return;
_audio = value;
libraryService.setLastAudio(value);
_setIsVideo();

_audioController.add(true);
}

final _isVideoController = StreamController<bool>.broadcast();
Stream<bool> get isVideoChanged => _isVideoController.stream;
void _setIsVideo() {
_isVideo = false;
for (var t in _videoTypes) {
if (audio?.url?.contains(t) == true) {
_isVideo = true;
break;
}
}
}

bool? _isVideo;
bool? get isVideo => _isVideo;
void setIsVideo(bool? value) {
if (value == _isVideo) return;
void _setIsVideo(bool? value) {
_isVideo = value;
_isVideoController.add(true);
}
Expand Down Expand Up @@ -193,7 +182,9 @@ class PlayerService {
? Media(audio!.url!)
: null;
if (media == null) return;
player.open(media);
player.open(media).then((_) {
player.state.tracks;
});
if (newPosition != null && _audio!.audioType != AudioType.radio) {
player.setVolume(0).then(
(_) => Future.delayed(const Duration(seconds: 3)).then(
Expand Down Expand Up @@ -257,6 +248,16 @@ class PlayerService {
_volume = value;
_volumeController.add(true);
});

_tracksSub = player.stream.tracks.listen((tracks) {
_setIsVideo(false);
for (var track in tracks.video) {
if (track.fps != null && track.fps! > 1) {
_setIsVideo(true);
break;
}
}
});
}

Future<void> playNext() async {
Expand Down Expand Up @@ -393,12 +394,11 @@ class PlayerService {
setDuration(playerState.$2);
}
if (playerState.$3 != null) {
_audio = playerState.$3;
_setAudio(playerState.$3);

if (_audio != null) {
await _setMediaControlsMetaData(audio!);
}
_setIsVideo();
}
}

Expand Down Expand Up @@ -639,43 +639,7 @@ class PlayerService {
await _durationSub?.cancel();
await _isCompletedSub?.cancel();
await _volumeSub?.cancel();
await _tracksSub?.cancel();
await player.dispose();
}
}

Set<String> _videoTypes = {
'.3g2',
'.3gp',
'.aaf',
'.asf',
'.avchd',
'.avi',
'.drc',
'.flv',
'.m2v',
'.m3u8',
'.m4p',
'.m4v',
'.mkv',
'.mng',
'.mov',
'.mp2',
'.mp4',
'.mpe',
'.mpeg',
'.mpg',
'.mpv',
'.mxf',
'.nsv',
'.ogg',
'.ogv',
'.qt',
'.rm',
'.rmvb',
'.roq',
'.svi',
'.vob',
'.webm',
'.wmv',
'.yuv',
};
Loading

0 comments on commit e6bb865

Please sign in to comment.