[Interest] iOS device volume control on iOS 12+ with Qt

Jason H jhihn at gmx.com
Wed Oct 16 22:43:47 CEST 2019


This solution had been working for me:
https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4/50740074#50740074

But it seems that I can't get away with an MPVolumeView anymore. However the proposed solution isn't working for me as I am not sure how to patch that into a Qt iOS app.
[UIApplication sharedApplication].windows is an array, but I am not sure what dragons are there with Qt.

Anyway, even patching in [UIApplication sharedApplication].windows[0] doesn't seem to be working.
I don't care about hiding the MPVolumeView. I just need it to work

void setVolume(double volume){
	UIWindow *mainWindow = [UIApplication sharedApplication].windows[0];
	//UIView *mainWindow = [UIView new];
	MPVolumeView *volumeView = [MPVolumeView new];
	UISlider *volumeViewSlider = nil;
	[mainWindow addSubview:volumeView];

	for (UIView *view in volumeView.subviews) {
	  if ([view isKindOfClass:[UISlider class]]) {
		volumeViewSlider = (UISlider *)view;
		break;
	  }
	}
	if (volumeViewSlider != nil) {
		dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
			volumeViewSlider.value = volume;
			NSLog(@"volumeViewSlider  set to %1.3f", volume);
		});
	} else {
		NSLog(@"volumeViewSlider is nil");
	}
}


More information about the Interest mailing list