Skip to content

Commit

Permalink
Feature/may changes 2 (jhomlala#490)
Browse files Browse the repository at this point in the history
* Dash (.mpd) support for audio, quality and subtitles (jhomlala#469)

* Generate DASH classes

* Generate BetterPlayerDashUtils to parse .mpd files

* Update data source to add Dash support

* .- Make player controller support Dash format source similar to Hls.
.- Update setAudioTrack method attribute type to dynamic to allow Hls or Dash audio track.

* Controls get audio, quality and subtitles info from dash also.

* Add name to subtitles

* If label not set use language

* Select by index if not label bug fixed

* update version to 0.0.66

* Unify HLS and DASH with ASMS (adaptive streaming media sources)

* Remove Videos from DASH and merge all video tracks in tracks adding mimetype to track

* Display mimeType in quialities row if track have it. To distingue same size videos with diferent mimeTypes.

* Refactor DashObject to BetterPlayerAsmsDataHolder and move to an independent file

* Unify ASMS utils and setup cotroller and generate parse method with the new BetterPlayerAsmsDataHolder class as response

* Added try catch to parse method

* Updated DASH stream code, general fixes, code format

* Updated DASH stream code, general fixes, code format

* Updated readme

* Fixed progress bar jumps when seeking video.

* Fixed progress bar jumps when seeking video.

* Fixed progress bar jumps when seeking video.

* Fix end of video looping final second, and video stutter during AudioSession Deactivation (jhomlala#473)

* fix: end of video looping final second

* fix: vid stutter due to active I/O during AudioSession Deactivation

* fix: stop audio session when no more players

* Updated changelog

* Updated codebase

* Updated codebase

Co-authored-by: Adrian <adrian@byvapps.com>
Co-authored-by: Nicholas Nagy <40705372+NicholasNagy@users.noreply.github.com>
  • Loading branch information
3 people authored May 19, 2021
1 parent 2ea18d8 commit 7c500c6
Show file tree
Hide file tree
Showing 27 changed files with 599 additions and 253 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.0.67
* Added support for DASH adaptive stream subtitles, audio tracks, tracks (by https://github.com/adrianByv)
* [BREAKING_CHANGE] Changed useHlsSubtitles, useHlsTracks, useHlsAudio to useAsmsSubtitles, useAsmsTracks, useAsmsAudio.
* Added DASH example.
* Fixed progress bar jumps when seeking video.
* Fixed end of video looping final second, and video stutter during AudioSession deactivation (by https://github.com/NicholasNagy)

## 0.0.66
* Added check in seek method to handle scenario when video wasn't ready to play.
* Added setupDataSourceList in BetterPlayerPlaylistController.
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is
✔️ BoxFit of video support
✔️ Playback speed support
✔️ HLS support (track, subtitles, audio track selection)
✔️ DASH support (track, subtitles, audio track selection)
✔️ Alternative resolution support
✔️ Cache support
✔️ Notifications support
Expand All @@ -94,7 +95,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.66
better_player: ^0.0.67
```
2. Install it
Expand Down Expand Up @@ -268,7 +269,7 @@ var dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
"https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8",
liveStream: false,
useHlsSubtitles: true,
useAsmsSubtitles: true,
hlsTrackNames: ["Low quality", "Not so low quality", "Medium quality"],
subtitles: [
BetterPlayerSubtitlesSource(
Expand Down Expand Up @@ -656,7 +657,7 @@ Use BetterPlayerDataSource.network to build network data source, BetterPlayerDat
to build memory data source.

Possible configuration options:
```
```dart
///Type of source of video
final BetterPlayerDataSourceType type;
Expand All @@ -673,14 +674,14 @@ Possible configuration options:
/// Custom headers for player
final Map<String, String> headers;
///Should player use hls subtitles. Default is true.
final bool useHlsSubtitles;
///Should player use hls / dash subtitles (ASMS - Adaptive Streaming Media Sources).
final bool useAsmsSubtitles;
///Should player use hls tracks
final bool useHlsTracks;
final bool useAsmsTracks;
///Should player use hls audio tracks
final bool useHlsAudioTracks;
///Should player use hls /das audio tracks
final bool useAsmsAudioTracks;
///List of strings that represents tracks names.
///If empty, then better player will choose name based on track parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ void setAudioTrack(String name, Integer index) {
return;
}
///Fallback option
if (hasElementWithoutLabel && name.equals(label)) {
if (hasElementWithoutLabel && index == groupIndex) {
setAudioTrack(rendererIndex, groupIndex, groupElementIndex);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,19 +377,19 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.jhomlala.betterPlayerExample;
PRODUCT_BUNDLE_IDENTIFIER = "com.jhomlala.better-player-example2";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -513,19 +513,19 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.jhomlala.betterPlayerExample;
PRODUCT_BUNDLE_IDENTIFIER = "com.jhomlala.better-player-example2";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand All @@ -544,19 +544,19 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.jhomlala.betterPlayerExample;
PRODUCT_BUNDLE_IDENTIFIER = "com.jhomlala.better-player-example2";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
2 changes: 2 additions & 0 deletions example/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ class Constants {
"https://proxy.uat.widevine.com/proxy?provider=widevine_test";
static String catImageUrl =
"https://img.webmd.com/dtmcms/live/webmd/consumer_assets/site_images/article_thumbnails/other/cat_relaxing_on_patio_other/1800x1200_cat_relaxing_on_patio_other.jpg";
static String dashStreamUrl =
"https://bitmovin-a.akamaihd.net/content/sintel/sintel.mpd";
}
52 changes: 52 additions & 0 deletions example/lib/pages/dash_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:better_player/better_player.dart';
import 'package:better_player_example/constants.dart';
import 'package:flutter/material.dart';

class DashPage extends StatefulWidget {
@override
_DashPageState createState() => _DashPageState();
}

class _DashPageState extends State<DashPage> {
late BetterPlayerController _betterPlayerController;

@override
void initState() {
BetterPlayerConfiguration betterPlayerConfiguration =
BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fit: BoxFit.contain,
);
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network, Constants.dashStreamUrl,
useAsmsSubtitles: true, useAsmsTracks: true);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Dash page"),
),
body: Column(
children: [
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
"Player with DASH audio tracks, subtitles and tracks.",
style: TextStyle(fontSize: 16),
),
),
AspectRatio(
aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController),
),
],
),
);
}
}
2 changes: 1 addition & 1 deletion example/lib/pages/hls_subtitles_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _HlsSubtitlesPageState extends State<HlsSubtitlesPage> {
);
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network, Constants.hlsPlaylistUrl,
useHlsSubtitles: true);
useAsmsSubtitles: true);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);
super.initState();
Expand Down
6 changes: 4 additions & 2 deletions example/lib/pages/hls_tracks_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ class _HlsTracksPageState extends State<HlsTracksPage> {
fit: BoxFit.contain,
);
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network, Constants.hlsTestStreamUrl,
useHlsSubtitles: true);
BetterPlayerDataSourceType.network,
Constants.hlsTestStreamUrl,
useAsmsSubtitles: true,
);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);
super.initState();
Expand Down
6 changes: 5 additions & 1 deletion example/lib/pages/welcome_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import 'package:better_player_example/constants.dart';
import 'package:better_player_example/pages/auto_fullscreen_orientation_page.dart';
import 'package:better_player_example/pages/basic_player_page.dart';
import 'package:better_player_example/pages/cache_page.dart';
import 'package:better_player_example/pages/change_player_theme_page.dart';
import 'package:better_player_example/pages/controller_controls_page.dart';
import 'package:better_player_example/pages/controls_always_visible_page.dart';
import 'package:better_player_example/pages/controls_configuration_page.dart';
import 'package:better_player_example/pages/custom_controls/change_player_theme_page.dart';
import 'package:better_player_example/pages/dash_page.dart';
import 'package:better_player_example/pages/drm_page.dart';
import 'package:better_player_example/pages/event_listener_page.dart';
import 'package:better_player_example/pages/fade_placeholder_page.dart';
Expand Down Expand Up @@ -156,6 +157,9 @@ class _WelcomePageState extends State<WelcomePage> {
_buildExampleElementWidget("DRM", () {
_navigateToPage(DrmPage());
}),
_buildExampleElementWidget("DASH", () {
_navigateToPage(DashPage());
}),
];
}

Expand Down
13 changes: 11 additions & 2 deletions ios/Classes/FLTBetterPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ - (void)itemDidPlayToEndTime:(NSNotification*)notification {
[ self removeObservers];

}
[_player pause];
_isPlaying = false;
_displayLink.paused = YES;
}
}

Expand Down Expand Up @@ -968,7 +971,10 @@ - (void) setRemoteCommandsNotificationActive{
}

- (void) setRemoteCommandsNotificationNotActive{
[[AVAudioSession sharedInstance] setActive:false error:nil];
if ([_players count] == 0) {
[[AVAudioSession sharedInstance] setActive:false error:nil];
}

[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
}

Expand Down Expand Up @@ -1178,6 +1184,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
}
result(nil);
} else if ([@"dispose" isEqualToString:call.method]) {
[player clear];
[self disposeNotificationData:player];
[self setRemoteCommandsNotificationNotActive];
[_registry unregisterTexture:textureId];
Expand All @@ -1198,7 +1205,9 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[player dispose];
}
});
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
if ([_players count] == 0) {
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
}
result(nil);
} else if ([@"setLooping" isEqualToString:call.method]) {
[player setIsLooping:[argsMap[@"looping"] boolValue]];
Expand Down
28 changes: 28 additions & 0 deletions lib/src/asms/better_player_asms_audio_track.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
///Representation of HLS / DASH audio track
class BetterPlayerAsmsAudioTrack {
///Audio index in DASH xml or Id of track inside HLS playlist
final int? id;

///segmentAlignment
final bool? segmentAlignment;

///Description of the audio
final String? label;

///Language code
final String? language;

///Url of audio track
final String? url;

///mimeType of the audio track
final String? mimeType;

BetterPlayerAsmsAudioTrack(
{this.id,
this.segmentAlignment,
this.label,
this.language,
this.url,
this.mimeType});
}
11 changes: 11 additions & 0 deletions lib/src/asms/better_player_asms_data_holder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:better_player/src/asms/better_player_asms_audio_track.dart';
import 'package:better_player/src/asms/better_player_asms_subtitle.dart';
import 'package:better_player/src/asms/better_player_asms_track.dart';

class BetterPlayerAsmsDataHolder {
List<BetterPlayerAsmsTrack>? tracks;
List<BetterPlayerAsmsSubtitle>? subtitles;
List<BetterPlayerAsmsAudioTrack>? audios;

BetterPlayerAsmsDataHolder({this.tracks, this.subtitles, this.audios});
}
28 changes: 28 additions & 0 deletions lib/src/asms/better_player_asms_subtitle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
///Representation of HLS / DASH subtitle element.
class BetterPlayerAsmsSubtitle {
///Language of the subtitle
final String? language;

///Name of the subtitle
final String? name;

///MimeType of the subtitle (DASH only)
final String? mimeType;

///Segment alignment (DASH only)
final bool? segmentAlignment;

///Url of the subtitle (master playlist)
final String? url;

///Urls of specific files
final List<String>? realUrls;

BetterPlayerAsmsSubtitle(
{this.language,
this.name,
this.mimeType,
this.segmentAlignment,
this.url,
this.realUrls});
}
Loading

0 comments on commit 7c500c6

Please sign in to comment.