Skip to content

Commit

Permalink
fix: Correctly update viewport when volume changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa committed Jun 7, 2024
1 parent e836a1b commit ca3e24d
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions lib/screens/layouts/desktop/viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import 'dart:async';

import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/providers/desktop_view_provider.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
Expand Down Expand Up @@ -102,28 +104,25 @@ class DesktopTileViewport extends StatefulWidget {

class _DesktopTileViewportState extends State<DesktopTileViewport> {
bool ptzEnabled = false;
late double? volume = widget.controller?.volume;

void updateVolume() {
if (widget.controller != null && mounted) {
setState(() => volume = widget.controller!.volume);
}
}
double get volume => widget.controller?.volume ?? 0.0;
StreamSubscription<double>? volumeSubscription;

@override
void initState() {
super.initState();
if (widget.controller != null) {
updateVolume();
volumeSubscription = widget.controller!.volumeStream.listen((event) {
if (mounted) {
setState(() {});
}
});
}
}

@override
void didUpdateWidget(covariant DesktopTileViewport oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller == null && widget.controller != null) {
updateVolume();
}
void dispose() {
volumeSubscription?.cancel();
super.dispose();
}

@override
Expand Down Expand Up @@ -244,13 +243,11 @@ class _DesktopTileViewportState extends State<DesktopTileViewport> {
tooltip:
isMuted ? loc.enableAudio : loc.disableAudio,
onPressed: () async {
if (isMuted) {
await widget.controller!.setVolume(1.0);
} else {
if (!isMuted) {
await widget.controller!.setVolume(0.0);
} else {
await widget.controller!.setVolume(1.0);
}

updateVolume();
},
),
if (isDesktopPlatform &&
Expand Down Expand Up @@ -343,7 +340,6 @@ class _DesktopTileViewportState extends State<DesktopTileViewport> {
device.preferredStreamingType !=
widget.device.preferredStreamingType,
);
updateVolume();
}
},
),
Expand Down

0 comments on commit ca3e24d

Please sign in to comment.