Set gain and expsoure without DisplayPropertyPage (Aforge, Directshow) - web-config

can anyone tell me how I can change gain or exposure with directshow from Afroge.
I already tried what you can see below but didn't succeed. What am I doing wrong?
Thanks in advance
using AForge.Video;
using AForge.Video.DirectShow;
...
...
VideoCaptureDevice videoSource;
private void changeProp(int value)
{
videoSource.SetCameraProperty(CameraControlProperty.Exposure, value, CameraControlFlags.Auto);
}

This code works for me. Most of the code taken from Afroge Samples.
private VideoCaptureDevice videoDevice;
private FilterInfoCollection videoDevices;
private VideoCapabilities[] videoCapabilities;
public Bool SetCamera(Cameras camera, int camDevice, CameraResolution camResolution,
int exposureValue, int zoomValue, int focusValue)
{
// Enumerate video devices
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
//Select camera according to specified index
videoDevice = new VideoCaptureDevice(videoDevices[camDevice].MonikerString);
//Get video capabilities for setting the resoluton
videoCapabilities = videoDevice.VideoCapabilities;
if (camera == Cameras.C910)
{
switch (camResolution)
{
case CameraResolution.A_640x480:
videoDevice.VideoResolution = videoCapabilities[0];
break;
case CameraResolution.B_800x600:
videoDevice.VideoResolution = videoCapabilities[14];
break;
case CameraResolution.C_960x720:
videoDevice.VideoResolution = videoCapabilities[16];
break;
case CameraResolution.D_1280x720:
videoDevice.VideoResolution = videoCapabilities[17];
break;
case CameraResolution.E_1920x1080:
videoDevice.VideoResolution = videoCapabilities[24];
break;
default:
videoDevice.VideoResolution = videoCapabilities[0];
break;
}
}
else if (camera == Cameras.C920)
{
switch (camResolution)
{
case CameraResolution.A_640x480:
videoDevice.VideoResolution = videoCapabilities[0];
break;
case CameraResolution.B_800x600:
videoDevice.VideoResolution = videoCapabilities[10];
break;
case CameraResolution.C_960x720:
videoDevice.VideoResolution = videoCapabilities[12];
break;
case CameraResolution.D_1280x720:
videoDevice.VideoResolution = videoCapabilities[14];
break;
case CameraResolution.E_1920x1080:
videoDevice.VideoResolution = videoCapabilities[16];
break;
default:
videoDevice.VideoResolution = videoCapabilities[0];
break;
}
}
else
{
videoDevice.VideoResolution = videoCapabilities[0];
}
try
{
videoDevice.SetCameraProperty(
CameraControlProperty.Zoom,
zoomValue,
CameraControlFlags.Manual);
videoDevice.SetCameraProperty(
CameraControlProperty.Focus,
focusValue,
CameraControlFlags.Manual);
videoDevice.SetCameraProperty(
CameraControlProperty.Exposure,
exposureValue,
CameraControlFlags.Manual);
}
catch (Exception ex)
{
MessageBox.show(ex.ToString());
}

Related

Music player playing two songs

I need to play the song after killing the app. songs are playing after killing them but now when I reopen the app it plays 2 songs at the same time is there any way to play a song from the same position and only one song play?
dependency= assets_audio_player
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.paused:
_state == AppLifecycleState;
break;
case AppLifecycleState.resumed:
_state == AppLifecycleState;
break;
case AppLifecycleState.inactive:
_state == AppLifecycleState;
break;
case AppLifecycleState.detached:
_state == AppLifecycleState;
break;
default:
}
if (_state == AppLifecycleState.detached) {
return null;
} else {
if (audioplayer.playerState.value == 'PlayerState.play') {
return null;
} else {
print('------------------state of player ${audioplayer.playerState.value}');
return setupPlaylist();
}
}
}

Is there a clean way of making an enum with associated value conform to rawRepresentable?

I have this in my code and it works, however if I have other enums (not necessarily color) with a long list it gets tiresome. Is there a better way of having an enum with an associated value that also conforms to RawRepresentable?
public enum IconColor {
case regular
case error
case warning
case success
case custom(String)
public var value: Color {
return loadColor(self.rawValue)
}
}
extension IconColor: RawRepresentable {
public var rawValue: String {
switch self {
case .regular: return "icon_regular"
case .error: return "icon_error"
case .warning: return "icon_warning"
case .success: return "icon_success"
case .custom(let value): return value
}
}
public init(rawValue: String) {
switch rawValue {
case "icon_regular": self = .regular
case "icon_error": self = .error
case "icon_warning": self = .warning
case "icon_success": self = .success
default: self = .custom(rawValue)
}
}
}
There's not a general solution.
public var rawValue: String {
switch self {
case .custom(let value): return value
default: return "icon_\(self)"
}
}
public init(rawValue: String) {
self =
[.regular, .error, .warning, .success]
.first { rawValue == $0.rawValue }
?? .custom(rawValue)
}

flutter audio manager onEvents not working

I am using AudioManager and I am going to check audio status (start, ready, play, pause, volume and so on). Sometimes onEvents function doesn't work.
AudioManager audioManager = AudioManager.instance;
bool _isLoading;
try {
_isLoading = true;
String result = await audioManager.startInfo(audio, auto: true);
print("start result $result");
audioManager.nextMode(playMode: PlayMode.single);
} catch (e) {
print(e);
}
audioManager.onEvents((events, args) {
print("$events, $args");
switch (events) {
case AudioManagerEvents.start:
_isLoading = true;
break;
case AudioManagerEvents.ready:
_isLoading = false;
break;
case AudioManagerEvents.seekComplete:
print("seek completed");
break;
case AudioManagerEvents.buffering:
_isLoading = false;
break;
case AudioManagerEvents.playstatus:
_isLoading = false;
break;
case AudioManagerEvents.timeupdate:
_isLoading = false;
audioManager.updateLrc(args["position"].toString());
break;
case AudioManagerEvents.error:
_isLoading = false;
break;
case AudioManagerEvents.ended:
audioManager.next();
break;
case AudioManagerEvents.volumeChange:
_volume = audioManager.volume;
break;
default:
_isLoading = false;
break;
}
setState(() {});
});
_isLoading is always true even if audio is playing now.

Is there a better way to do this switch?

What I'm trying to do is: that based on the notification type, I'll change the image of the tableViewCell, and I know that maybe there is a better way of achieving this. I thought that maybe using enums would be a good way, but there is a lot of code in here, and it will do nothing but grow with time.
Is there a better way of achieving this?
enum NotificationIcons {
case newPayment
case newPaymentMethod
case newOffers
case userInfoUpdate
case supportChat
case newAnnouncement
case cardVerification
var strings: String {
switch self {
case .newPayment:
return "new_payment"
case .newPaymentMethod:
return "new_payment_method"
case .newOffers:
return "new_offers"
case .userInfoUpdate:
return "user_info_update"
case .supportChat:
return "support_chat"
case .newAnnouncement:
return "new_announcement"
case .cardVerification:
return "card_verification"
}
}
var image: UIImage {
switch self {
case .newPayment: return UIImage(named: "Icon-notification-service-pay")!
case .newPaymentMethod: return UIImage(named: "Icon-notification-add-paycard")!
case .newOffers: return UIImage(named: "Icon-notification-promos")!
case .userInfoUpdate: return UIImage(named: "Icon-notification-update-data")!
case .supportChat: return UIImage(named: "Icon-notification-support")!
case .newAnnouncement: return UIImage(named: "Icon-notification-advice")!
case .cardVerification: return UIImage(named: "Icon-notification-add-paycard")!
}
}
var detailImage: UIImage {
switch self {
case .newPayment: return UIImage(named: "Icon-notification-detail-service-pay")!
case .newPaymentMethod: return UIImage(named: "Icon-notification-detail-add-paycard")!
case .newOffers: return UIImage(named: "Icon-notification-detail-promos")!
case .userInfoUpdate: return UIImage(named: "Icon-notification-detail-update-data")!
case .supportChat: return UIImage(named: "Icon-notification-detail-support")!
case .newAnnouncement: return UIImage(named: "Icon-notification-detail-advice")!
case .cardVerification: return UIImage(named: "Icon-notification-detail-add-paycard")!
}
}
}
Inside my tableViewCell I have this variable notification which starts to set all values on didSet
switch notification.type {
case NotificationIcons.newPayment.strings:
notificationImageView.image = NotificationIcons.newPayment.image
break
case NotificationIcons.newPaymentMethod.strings:
notificationImageView.image = NotificationIcons.newPaymentMethod.image
break
case NotificationIcons.newOffers.strings:
notificationImageView.image = NotificationIcons.newPaymentMethod.image
break
case NotificationIcons.userInfoUpdate.strings:
notificationImageView.image = NotificationIcons.newPaymentMethod.image
break
case NotificationIcons.supportChat.strings:
notificationImageView.image = NotificationIcons.newPaymentMethod.image
break
case NotificationIcons.newAnnouncement.strings:
notificationImageView.image = NotificationIcons.newPaymentMethod.image
break
case NotificationIcons.cardVerification.strings:
notificationImageView.image = NotificationIcons.newPaymentMethod.image
break
default:
break
}
Firstly, assign rawValue of type String to the NotificationIcons enum, like this:
enum NotificationIcons: String {
case newPayment = "new_payment"
//...
}
Then, modify the switch statement with an initializer:
guard let type = NotificationIcons(rawValue: notification.type) else { return }
notinotificationImageView.image = type.image

Concurrent race-condition function in Swift 5

I have the following code which should return the setting of the NotificationCenter, but when I run this code the variable notificationSetting returns nothing.
How can I solve this so that the application waits for the result?
func getNotificationSetting() -> String{
var notificationSetting = ""
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
switch settings.authorizationStatus {
case .authorized, .provisional:
notificationSetting = "Authorized"
case .denied:
notificationSetting = "Denied"
case .notDetermined:
notificationSetting = "NotDetermined"
#unknown default:
notificationSetting = "NotDetermined"
}
}
return notificationSetting
}
getNotificationSettings execute asynchronously.
func getNotificationSetting(completionHandler: #escaping (String) -> Void) {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
switch settings.authorizationStatus {
case .authorized, .provisional:
completionHandler("Authorized")
case .denied:
completionHandler("Denied")
case .notDetermined:
completionHandler("NotDetermined")
#unknown default:
completionHandler("NotDetermined")
}
}
}
func getSettings() {
self.getNotificationSetting(completionHandler: { (notificationSetting) in
// do what you want
print(notificationSetting)
})
}