-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support subtitles with 0.2.0 version.
- Loading branch information
Showing
19 changed files
with
492 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
## [0.0.1] - TODO: Add release date. | ||
## [0.1.0] - Spring. | ||
|
||
* TODO: Describe initial release. | ||
* Added `IQScreen` class that enable user to use a plyer as a screen. | ||
|
||
## [0.2.0] - Storm. | ||
|
||
* Added `SubtitleProvider` class that enable user to use a subtitle from files, assets, network, string. | ||
* Added `IQParser` class to display subtitle data. | ||
* Added `SubtitleBloc` class to use with `IQParser`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
library iqplayer; | ||
|
||
export 'src/ui/iqscreen.dart'; | ||
export 'package:video_player/video_player.dart'; | ||
export 'src/utils/subtitle_provider.dart'; | ||
export 'src/ui/iqparser.dart'; | ||
export 'package:video_player/video_player.dart' | ||
show VideoPlayerController, VideoPlayerValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export 'screen_bloc.dart'; | ||
export 'screen_event.dart'; | ||
export 'screen_state.dart'; | ||
export 'screen_state.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'subtitle_bloc.dart'; | ||
export 'subtitle_event.dart'; | ||
export 'subtitle_state.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:async'; | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:iqplayer/src/models/subtitle.dart'; | ||
import 'package:iqplayer/src/utils/subtitle_provider.dart'; | ||
import 'package:iqplayer/src/utils/subtitle_controller.dart'; | ||
import './bloc.dart'; | ||
|
||
class SubtitleBloc extends Bloc<SubtitleEvent, SubtitleState> { | ||
final SubtitleProvider _subtitleProvider; | ||
final SubtitleController _subtitleController; | ||
|
||
List<Subtitle> subtitles; | ||
|
||
SubtitleBloc(this._subtitleProvider) | ||
: subtitles = new List<Subtitle>(), | ||
_subtitleController = new SubtitleController(); | ||
|
||
@override | ||
SubtitleState get initialState => SubtitleState.initial(); | ||
|
||
@override | ||
Stream<SubtitleState> mapEventToState( | ||
SubtitleEvent event, | ||
) async* { | ||
if (event is FetchSubtitles) { | ||
subtitles = await _subtitleController.fetchList(_subtitleProvider.data); | ||
} | ||
|
||
if (event is UpdateSubtitle) { | ||
for (Subtitle subtitle in subtitles) { | ||
if (event.position >= subtitle.start && | ||
event.position <= subtitle.end) { | ||
yield SubtitleState(subtitle.data); | ||
break; | ||
} else { | ||
yield SubtitleState.initial(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:equatable/equatable.dart'; | ||
|
||
abstract class SubtitleEvent extends Equatable { | ||
const SubtitleEvent(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
class FetchSubtitles extends SubtitleEvent {} | ||
|
||
class UpdateSubtitle extends SubtitleEvent { | ||
final Duration position; | ||
|
||
const UpdateSubtitle(this.position); | ||
|
||
@override | ||
List<Object> get props => [position]; | ||
|
||
@override | ||
String toString() => "Position { duration: $position }"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:iqplayer/src/models/subtitle.dart'; | ||
|
||
class SubtitleState extends Equatable { | ||
final String data; | ||
|
||
const SubtitleState(this.data); | ||
|
||
factory SubtitleState.initial() => SubtitleState( | ||
'' | ||
); | ||
|
||
SubtitleState copyWith(Subtitle subtitle) => | ||
SubtitleState(subtitle.data ?? this.data); | ||
|
||
@override | ||
List<Object> get props => [data]; | ||
|
||
@override | ||
String toString() => "SubtitleState { date: $data }"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:meta/meta.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class Subtitle extends Equatable { | ||
final Duration start; | ||
final Duration end; | ||
final String data; | ||
|
||
const Subtitle({ | ||
@required this.start, | ||
@required this.end, | ||
@required this.data, | ||
}) : assert(start != null), | ||
assert(end != null), | ||
assert(data != null); | ||
|
||
bool operator >(Subtitle other) => this.start > other.start; | ||
|
||
bool operator <(Subtitle other) => this.start < other.start; | ||
|
||
bool operator <=(Subtitle other) => this.start <= other.start; | ||
|
||
bool operator >=(Subtitle other) => this.start >= other.start; | ||
|
||
int compareTo(Subtitle other) => | ||
this.start.inMilliseconds.compareTo(other.start.inMilliseconds); | ||
|
||
@override | ||
List<Object> get props => [start, end, data]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/services.dart'; | ||
import 'package:http/http.dart'; | ||
|
||
class SubtitleRepository { | ||
Future<String> fetchFromNetwork(String url) async { | ||
final response = await get(url); | ||
if (response.statusCode == 200) return utf8.decode(response.bodyBytes); | ||
throw 'ERROR_FETCH_SUBTITLE(${response.statusCode})'; | ||
} | ||
|
||
Future<String> fetchFromFile(File file) async { | ||
return await file.readAsString(); | ||
} | ||
|
||
Future<String> fetchFromAssets(String path) async { | ||
return await rootBundle.loadString(path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:iqplayer/src/blocs/player/bloc.dart'; | ||
import 'package:iqplayer/src/blocs/subtitle/bloc.dart'; | ||
|
||
class IQParser extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return BlocListener<PlayerBloc, PlayerState>( | ||
bloc: BlocProvider.of<PlayerBloc>(context), | ||
listener: (context, state) { | ||
if (state is PlayingState) | ||
BlocProvider.of<SubtitleBloc>(context).add( | ||
UpdateSubtitle(state.position), | ||
); | ||
}, | ||
child: BlocBuilder<SubtitleBloc, SubtitleState>( | ||
bloc: BlocProvider.of<SubtitleBloc>(context), | ||
builder: (context, state) => Container( | ||
width: MediaQuery.of(context).size.width, | ||
child: Text( | ||
state.data, | ||
textAlign: TextAlign.center, | ||
style: TextStyle( | ||
fontSize: 20, | ||
color: Colors.white, | ||
shadows: [ | ||
Shadow( | ||
color: Colors.black, | ||
offset: Offset(1, 1), | ||
blurRadius: 2.5, | ||
) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.