Skip to content

Commit abea8fa

Browse files
authored
Add Volume options (#86)
1 parent 5551e02 commit abea8fa

File tree

8 files changed

+59
-68
lines changed

8 files changed

+59
-68
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.5
2+
* Updates MobileVLC to allow for changing of volume. Example Updated Also.
3+
credits to Mitch Ross (https://github.com/mitchross)
4+
15
## 3.0.4
26
* Updates MobileVLC to allow for options as flags and hardware acceleration/
37
credits to pharshdev (https://github.com/pharshdev) and Mitch Ross (https://github.com/mitchross)

android/src/main/java/software/solid/fluttervlcplayer/FlutterVideoView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ public void onMethodCall(MethodCall methodCall, @NonNull MethodChannel.Result re
243243

244244
result.success(null);
245245
break;
246+
247+
case "setVolume":
248+
int volume = 100;
249+
volume = methodCall.argument("volume");
250+
mediaPlayer.setVolume(volume);
251+
result.success(null);
252+
break;
253+
254+
246255
}
247256
}
248257

example/ios/Flutter/.last_build_id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f1df2ffda6f2083c9121914530433089
1+
b51a9eab8a58462f1b870a104119b683

example/ios/Podfile

100755100644
Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,32 @@ project 'Runner', {
1010
'Release' => :release,
1111
}
1212

13-
def parse_KV_file(file, separator='=')
14-
file_abs_path = File.expand_path(file)
15-
if !File.exists? file_abs_path
16-
return [];
13+
def flutter_root
14+
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15+
unless File.exist?(generated_xcode_build_settings_path)
16+
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
1717
end
18-
generated_key_values = {}
19-
skip_line_start_symbols = ["#", "/"]
20-
File.foreach(file_abs_path) do |line|
21-
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
22-
plugin = line.split(pattern=separator)
23-
if plugin.length == 2
24-
podname = plugin[0].strip()
25-
path = plugin[1].strip()
26-
podpath = File.expand_path("#{path}", file_abs_path)
27-
generated_key_values[podname] = podpath
28-
else
29-
puts "Invalid plugin specification: #{line}"
30-
end
18+
19+
File.foreach(generated_xcode_build_settings_path) do |line|
20+
matches = line.match(/FLUTTER_ROOT\=(.*)/)
21+
return matches[1].strip if matches
3122
end
32-
generated_key_values
23+
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
3324
end
3425

26+
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27+
28+
flutter_ios_podfile_setup
29+
3530
target 'Runner' do
3631
use_frameworks!
3732
use_modular_headers!
3833

39-
# Flutter Pod
40-
41-
copied_flutter_dir = File.join(__dir__, 'Flutter')
42-
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
43-
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
44-
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
45-
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
46-
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
47-
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
48-
49-
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
50-
unless File.exist?(generated_xcode_build_settings_path)
51-
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
52-
end
53-
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
54-
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
55-
56-
unless File.exist?(copied_framework_path)
57-
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
58-
end
59-
unless File.exist?(copied_podspec_path)
60-
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
61-
end
62-
end
63-
64-
# Keep pod path relative so it can be checked into Podfile.lock.
65-
pod 'Flutter', :path => 'Flutter'
66-
67-
# Plugin Pods
68-
69-
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
70-
# referring to absolute paths on developers' machines.
71-
system('rm -rf .symlinks')
72-
system('mkdir -p .symlinks/plugins')
73-
plugin_pods = parse_KV_file('../.flutter-plugins')
74-
plugin_pods.each do |name, path|
75-
symlink = File.join('.symlinks', 'plugins', name)
76-
File.symlink(path, symlink)
77-
pod name, :path => File.join(symlink, 'ios')
78-
end
34+
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
7935
end
8036

8137
post_install do |installer|
8238
installer.pods_project.targets.each do |target|
83-
target.build_configurations.each do |config|
84-
config.build_settings['ENABLE_BITCODE'] = 'NO'
85-
end
39+
flutter_additional_ios_build_settings(target)
8640
end
8741
end

example/lib/main.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MyAppScaffoldState extends State<MyAppScaffold> {
3131
bool isPlaying = true;
3232
double sliderValue = 0.0;
3333
double currentPlayerTime = 0;
34+
double volumeValue = 100;
3435

3536
@override
3637
void initState() {
@@ -82,7 +83,7 @@ class MyAppScaffoldState extends State<MyAppScaffold> {
8283
child: new VlcPlayer(
8384
aspectRatio: 16 / 9,
8485
url:
85-
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4",
86+
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4",
8687
controller: _videoViewController,
8788
// Play with vlc options
8889
options: [
@@ -91,7 +92,8 @@ class MyAppScaffoldState extends State<MyAppScaffold> {
9192
'--no-skip-frames',
9293
'--rtsp-tcp'
9394
],
94-
hwAcc: HwAcc.DISABLED, // or {HwAcc.AUTO, HwAcc.DECODING, HwAcc.FULL}
95+
hwAcc: HwAcc
96+
.DISABLED, // or {HwAcc.AUTO, HwAcc.DECODING, HwAcc.FULL}
9597
placeholder: Container(
9698
height: 250.0,
9799
child: Row(
@@ -117,6 +119,7 @@ class MyAppScaffoldState extends State<MyAppScaffold> {
117119
),
118120
),
119121
),
122+
Text("Seek"),
120123
Slider(
121124
activeColor: Colors.white,
122125
value: sliderValue,
@@ -135,6 +138,18 @@ class MyAppScaffoldState extends State<MyAppScaffold> {
135138
FlatButton(
136139
child: isPlaying ? Icon(Icons.pause) : Icon(Icons.play_arrow),
137140
onPressed: () => {playOrPauseVideo()}),
141+
Text("Volume Level"),
142+
Slider(
143+
min: 0,
144+
max: 100,
145+
value: volumeValue,
146+
onChanged: (value) {
147+
setState(() {
148+
volumeValue = value;
149+
});
150+
_videoViewController2.setVolume(volumeValue.toInt());
151+
},
152+
),
138153
FlatButton(
139154
child: Text("Change URL"),
140155
onPressed: () => _videoViewController.setStreamUrl(

ios/Classes/SwiftFlutterVlcPlayerPlugin.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,12 @@ public class VLCView: NSObject, FlutterPlatformView {
138138
let newTime = NSNumber(value:(setTimeInMillisecondsAsString! as NSString).doubleValue)
139139
let time = VLCTime(number: newTime )
140140
self.player.time = time
141-
142-
141+
result(nil)
142+
return
143+
144+
case .setVolume:
145+
let setVolume = arguments["volume"] as? Int32
146+
self.player.audio.volume = setVolume ?? 100
143147
result(nil)
144148
return
145149

@@ -202,7 +206,7 @@ class VLCPlayerEventStreamHandler:NSObject, FlutterStreamHandler, VLCMediaPlayer
202206
}
203207

204208
}
205-
209+
206210
switch player?.state {
207211

208212
case .esAdded, .buffering, .opening:
@@ -303,4 +307,5 @@ enum FlutterMethodCallOption :String {
303307
case getSnapshot = "getSnapshot"
304308
case setPlaybackSpeed = "setPlaybackSpeed"
305309
case setTime = "setTime"
310+
case setVolume = "setVolume"
306311
}

lib/flutter_vlc_player.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ class VlcPlayerController {
347347
await _methodChannel.invokeMethod("setTime", {'time': time.toString()});
348348
}
349349

350+
Future<void> setVolume(int volume) async {
351+
await _methodChannel.invokeMethod("setVolume", {'volume': volume});
352+
}
353+
350354
Future<void> setPlaybackSpeed(double speed) async {
351355
await _methodChannel
352356
.invokeMethod("setPlaybackSpeed", {'speed': speed.toString()});

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_vlc_player
22
description: A VLC-powered alternative to Flutter's video_player. Supports multiple players on one screen.
3-
version: 3.0.4
3+
version: 3.0.5
44
homepage: https://github.com/solid-software/flutter_vlc_player
55

66
environment:

0 commit comments

Comments
 (0)