Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from jonatadashi/develop
Browse files Browse the repository at this point in the history
2.0.1
  • Loading branch information
jonafeucht committed Mar 24, 2021
2 parents e5708f8 + 1fa622a commit ea57eb8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 60 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1
- Fix `Unhandled Exception: Null check operator used on a null value`
Added showTopMenu as requested in [#12](https://github.com/jonatadashi/youtube_plyr_iframe/issues/12).

## 2.0.0
- 💪 Running with sound null safety 💪
- Minor fix
Expand All @@ -12,6 +16,9 @@
## 2.0.0-nullsafety.1
- 💪 Running with sound null safety 💪 (Almost)

## 1.3.7
- Fixed on pause not displaying correctly

## 1.3.6+1
- Added example app

Expand Down
17 changes: 10 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:youtube_player_iframe_example/pages/oldDemo.dart';
import 'package:youtube_player_iframe_example/pages/thumbnailDemo.dart';
import 'package:youtube_plyr_iframe/youtube_plyr_iframe.dart';
Expand Down Expand Up @@ -221,8 +218,12 @@ class YoutubeViewer extends StatefulWidget {
}

class _YoutubeViewerState extends State<YoutubeViewer> {
// ignore: close_sinks
YoutubePlayerController? _controller;
late YoutubePlayerController _controller;
@override
void dispose() {
_controller.showTopMenu();
super.dispose();
}

@override
void initState() {
Expand All @@ -242,8 +243,9 @@ class _YoutubeViewerState extends State<YoutubeViewer> {
),
)..listen((value) {
if (value.isReady && !value.hasPlayed) {
_controller!
_controller
..hidePauseOverlay()

// Uncomment below to stop Autoplay
// ..play()
..hideTopMenu();
Expand Down Expand Up @@ -274,7 +276,8 @@ class _YoutubeViewerState extends State<YoutubeViewer> {
Widget build(BuildContext context) {
final player = YoutubePlayerIFrame();
return YoutubePlayerControllerProvider(
controller: _controller!,
key: UniqueKey(),
controller: _controller,
child: AlertDialog(
insetPadding: EdgeInsets.all(10),
backgroundColor: Colors.black,
Expand Down
87 changes: 48 additions & 39 deletions example/lib/pages/oldDemo.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:youtube_player_iframe_example/widgets/meta_data_section.dart';
Expand All @@ -14,8 +16,7 @@ class OldDemo extends StatefulWidget {
}

class _YoutubeAppDemoState extends State<OldDemo> {
// ignore: close_sinks
YoutubePlayerController? _controller;
late YoutubePlayerController _controller;

@override
void initState() {
Expand All @@ -42,10 +43,8 @@ class _YoutubeAppDemoState extends State<OldDemo> {
),
)..listen((value) {
if (value.isReady && !value.hasPlayed) {
_controller!
_controller
..hidePauseOverlay()
// Uncomment below to start autoplay on iOS
//..play()
..hideTopMenu();
}
});
Expand Down Expand Up @@ -74,44 +73,54 @@ class _YoutubeAppDemoState extends State<OldDemo> {
const player = YoutubePlayerIFrame();
return YoutubePlayerControllerProvider(
// Passing controller to widgets below.
controller: _controller!,
child: Scaffold(
appBar: AppBar(
title: const Text('Youtube Plyr Demo'),
),
body: LayoutBuilder(
builder: (context, constraints) {
if (kIsWeb && constraints.maxWidth > 800) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Expanded(child: player),
const SizedBox(
width: 500,
child: SingleChildScrollView(
child: Controls(),
),
),
],
);
}
return ListView(
children: [
player,
const Controls(),
],
);
},
),
controller: _controller,
child: YoutubeValueBuilder(
key: UniqueKey(),
builder: (context, value) {
if (value!.isReady && !value.hasPlayed) {
Timer(Duration(seconds: 5), () {
_controller.showTopMenu();
});
}
return Scaffold(
appBar: AppBar(
title: const Text('Youtube Plyr Demo'),
),
body: LayoutBuilder(
builder: (context, constraints) {
if (kIsWeb && constraints.maxWidth > 800) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Expanded(child: player),
const SizedBox(
width: 500,
child: SingleChildScrollView(
child: Controls(),
),
),
],
);
}
return ListView(
children: [
player,
const Controls(),
],
);
},
),
);
},
),
);
}

// @override
// void dispose() {
// _controller.close();
// super.dispose();
// }
@override
void dispose() {
_controller.showTopMenu();
super.dispose();
}
}

///
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: youtube_player_iframe_example
description: Demonstrates how to use the youtube_plyr_iframe plugin.
version: 2.0.0
version: 2.0.1
publish_to: none

environment:
sdk: '>=2.12.0-0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down
3 changes: 3 additions & 0 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class YoutubePlayerController extends Stream<YoutubePlayerValue>
/// Might violates Youtube's TOS. Use at your own risk.
void hideTopMenu() => invokeJavascript('hideTopMenu()');

/// Show top menu
void showTopMenu() => invokeJavascript('showTopMenu()');

/// Hides pause overlay i.e. related videos shown when player is paused.
///
/// Might violates Youtube's TOS. Use at your own risk.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/helpers/player_fragments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ function hideTopMenu() {
try { document.querySelector('#player').contentDocument.querySelector('.ytp-chrome-top').style.display = 'none'; } catch(e) { }
return '';
}
function showTopMenu() {
try { document.querySelector('#player').contentDocument.querySelector('.ytp-chrome-top').style.display = ''; } catch(e) { }
return '';
}
function hidePauseOverlay() {
try { document.querySelector('#player').contentDocument.querySelector('.ytp-pause-overlay').style.display = 'none'; } catch(e) { }
return '';
Expand Down
10 changes: 0 additions & 10 deletions lib/src/players/youtube_player_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ class _MobileYoutubePlayerState extends State<RawYoutubePlayer>
),
android: AndroidInAppWebViewOptions(useWideViewPort: false),
),
// shouldOverrideUrlLoading: (_, detail) async {
// final uri = Uri.parse(detail.url);
// final feature = uri.queryParameters['feature'];
// if (feature == 'emb_rel_pause') {
// controller.load(uri.queryParameters['v']);
// } else {
// return ShouldOverrideUrlLoadingAction.ALLOW;
// }
// return ShouldOverrideUrlLoadingAction.CANCEL;
// },
onWebViewCreated: (webController) {
if (!_webController.isCompleted) {
_webController.complete(webController);
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: youtube_plyr_iframe
description: Fork of Youtube Player Iframe. Supports web & mobile platforms.
version: 2.0.0
version: 2.0.1
repository: https://github.com/jonatadashi/youtube_plyr_iframe
homepage: https://github.com/jonatadashi/youtube_plyr_iframe

environment:
sdk: '>=2.12.0-0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'
flutter: '>=1.22.0'

dependencies:
Expand Down

0 comments on commit ea57eb8

Please sign in to comment.