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

Play youtube live stream from a channel id #550

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ YoutubePlayerControllerProvider( // Provides controller to all the widget below
// Access the controller as: `YoutubePlayerControllerProvider.of(context)` or `controller.ytController`.
```

#### Using the player

```dart
YoutubePlayerController _controller = YoutubePlayerController(
initialVideoId: 'NpEaa2P7qZI',
channelId: 'UCLA_DiR1FfKNvjuUpBHmylQ',
params: YoutubePlayerParams(
showControls: true,
showFullscreenButton: true,
),
);
```

## Want to customize the player?
The package provides `YoutubeValueBuilder`, which can be used to create any custom controls.

Expand Down
13 changes: 13 additions & 0 deletions packages/youtube_player_iframe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ YoutubePlayerControllerProvider( // Provides controller to all the widget below
// Access the controller as: `YoutubePlayerControllerProvider.of(context)` or `controller.ytController`.
```

#### Using the player

```dart
YoutubePlayerController _controller = YoutubePlayerController(
initialVideoId: 'NpEaa2P7qZI',
channelId: 'UCLA_DiR1FfKNvjuUpBHmylQ',
params: YoutubePlayerParams(
showControls: true,
showFullscreenButton: true,
),
);
```

## Want to customize the player?
The package provides `YoutubeValueBuilder`, which can be used to create any custom controls.

Expand Down
4 changes: 4 additions & 0 deletions packages/youtube_player_iframe/lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class YoutubePlayerController {
/// Creates [YoutubePlayerController].
YoutubePlayerController({
required this.initialVideoId,
this.channelId,
this.params = const YoutubePlayerParams(),
}) {
invokeJavascript = (_) async {};
Expand All @@ -33,6 +34,9 @@ class YoutubePlayerController {
/// The Youtube video id for initial video to be loaded.
final String initialVideoId;

/// The optional channel id to display a live stream from a channel.
final String? channelId;

/// Defines default parameters for the player.
final YoutubePlayerParams params;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:developer';

import 'package:youtube_player_iframe/youtube_player_iframe.dart';

///
Expand Down Expand Up @@ -25,12 +27,18 @@ String youtubeIFrameTag(YoutubePlayerController controller) {
if (controller.params.playlist.isNotEmpty)
'playlist': '${controller.params.playlist.join(',')}'
};
if (controller.channelId != null) {
params['channel'] = controller.channelId as String;
}
final youtubeAuthority = controller.params.privacyEnhanced
? 'www.youtube-nocookie.com'
: 'www.youtube.com';
final embedUrl = controller.channelId != null
? 'embed/live_stream'
: 'embed/${controller.initialVideoId}';
final sourceUri = Uri.https(
youtubeAuthority,
'embed/${controller.initialVideoId}',
embedUrl,
params,
);
return '<iframe id="player" type="text/html"'
Expand Down