Prevent error "funk" sound in event monitor OS X - swift

I'm writing an app in swift that lives in the menu bar at the top of the screen. I need both a global and local event monitor to open the popover on a specific key press. There is no problem with the local event monitor, but when the user hits the key command (cmd+shift+8) from inside an app like Finder, the popover opens but the mac error "Funk" sound is played as well. Is there any way I can disable this? Perhaps some way for the app to eat the sound, or register it as a valid keyboard shortcut so the sound is never played?
Here is the code:
NSEvent.addGlobalMonitorForEvents(matching: NSEventMask.keyDown, handler: {(event: NSEvent!) -> Void in
if (event.keyCode == 28 && event.modifierFlags.contains(NSEventModifierFlags.command) && event.modifierFlags.contains(NSEventModifierFlags.shift)){
self.togglePopover(sender: self)
}
});
NSEvent.addLocalMonitorForEvents(matching: NSEventMask.keyDown, handler: {(event: NSEvent!) -> NSEvent? in
if (event.keyCode == 28 && event.modifierFlags.contains(NSEventModifierFlags.command) && event.modifierFlags.contains(NSEventModifierFlags.shift)){
self.togglePopover(sender: self)
}
return event
});

I ended up using MASShortcut as a workaround solution to this issue.

In your addGlobalMonitorForEventsMatchingMask handler, save the current volume level and turn the volume down on both channels. You can do you own event processing in the handler before or after turning down the volume.
Before returning from the handler, restore the original volume, but include a delay to give the OS time to process the event (it will send the "funk," but you won't hear it).
One side effect: if you're listening to something (e.g., music), that will be briefly silenced, too.
My event code:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSEventMaskKeyDown
handler:^(NSEvent *event) {
if ( event.type == NSEventTypeKeyDown ) {
if ( event.keyCode == 106 ) { // F16
// process the event here
[self adjustVolume:#(NO)];
[self performSelector:#selector(adjustVolume:) withObject:#(YES) afterDelay:0.3];
// 0.2 seconds was too soon
}
}
}];
My volume adjustment code:
- (void)adjustVolume:(NSNumber *)offOn
{
// get audio device...
AudioObjectPropertyAddress getDefaultOutputDevicePropertyAddress = {
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
AudioDeviceID defaultOutputDeviceID;
UInt32 infoSize = sizeof(defaultOutputDeviceID);
AudioObjectGetPropertyData(kAudioObjectSystemObject,
&getDefaultOutputDevicePropertyAddress,
0, NULL,
&infoSize, &defaultOutputDeviceID);
// structurs to access the left/right volume setting
AudioObjectPropertyAddress volumePropertyAddress1 = {
kAudioDevicePropertyVolumeScalar,
kAudioDevicePropertyScopeOutput,
1 /* left */
};
AudioObjectPropertyAddress volumePropertyAddress2 = {
kAudioDevicePropertyVolumeScalar,
kAudioDevicePropertyScopeOutput,
2 /* right */
};
// save the original volume (assumes left/right are the same
static Float32 volumeOriginal; // could be an iVar
if ( offOn.boolValue == NO ) { // turn off
UInt32 volumedataSize = sizeof(volumeOriginal);
AudioObjectGetPropertyData(defaultOutputDeviceID,
&volumePropertyAddress1,
0, NULL,
&volumedataSize, &volumeOriginal);
//NSLog(#"volumeOriginal %f",volumeOriginal);
// turn off both channels
Float32 volume = 0.0;
AudioObjectSetPropertyData(defaultOutputDeviceID,
&volumePropertyAddress1,
0, NULL,
sizeof(volume), &volume);
AudioObjectSetPropertyData(defaultOutputDeviceID,
&volumePropertyAddress2,
0, NULL,
sizeof(volume), &volume);
} else { // restore
//NSLog(#"restoring volume");
AudioObjectSetPropertyData(defaultOutputDeviceID,
&volumePropertyAddress1,
0, NULL,
sizeof(volumeOriginal), &volumeOriginal);
AudioObjectSetPropertyData(defaultOutputDeviceID,
&volumePropertyAddress2,
0, NULL,
sizeof(volumeOriginal), &volumeOriginal);
}
}
With recognition to Thomas O'Dell for getting me started on this Change OS X system volume programmatically

Related

Why does the button get unhighlighted after repuasing?

I'm facing a really weird issue with the pause menu.
Whenever I pause and then unpause and pause again, the buttons lose their focus.
The first time I pause:
Second time I pause:
Only the first time is working as expected, all pauses after that are like the second image(no button highlighted). I couldn't figure out the reason.
Here is my code:
void Update()
{
var gamepad = Gamepad.current;
var keyboard = Keyboard.current;
if (gamepad == null && keyboard == null)
return; // No gamepad connected.
if ((gamepad != null && gamepad.startButton.wasPressedThisFrame) || (keyboard !=null && keyboard.pKey.wasPressedThisFrame))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
player.gameObject.GetComponent<MyPlayerMovement>().enabled = true;
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
// GameObject.Find("ThePlayer").GetComponent<MyPlayerMovement>().enabled = false;
// GameObject.Find("ThePlayer").GetComponent<InteractIcons>().enabled = false;
}
private void Pause()
{
player.gameObject.GetComponent<MyPlayerMovement>().enabled = false;
pauseMenuUI.SetActive(true);
resumeBtn.Select();
Time.timeScale = 0f;
GameIsPaused = true;
// GameObject.Find("ThePlayer").GetComponent<MyPlayerMovement>().enabled = true;
// GameObject.Find("ThePlayer").GetComponent<InteractIcons>().enabled = true;
}
I tried assigning the button in the inspector to a variable and then added this variable like so resumeBtn.Select(); in Pause() but it changed nothing.
Note that when the buttons are not highlighted, they get highlighted only after I press the arrows up or down or move the gamepad's analogue stick up or down. but at first, they are not highlighted. How can I fix this?
In your event system you specified first selected to you resume button, however that seems to be not enough.
I'm not really sure how it works (this paragraph may be absolute bs), but after empirical research I think that event system sets its current selected item to the first selected reference during its awake or start. On disable, it seems to clear its current selected, but doesn't set it again on its enable.
One way to tackle this problem is to manually set current selected item when bringing up pause menu: eventSystem.SetSelectedGameObject(resumeButtonGameObject); where eventSystem is obviousely of EventSystem type.

How to code latch switch function using STM32?

I am looking a code to get the latch switch function using STM32.
The below code which I have tried is working in stm32 but only a push button function without latch.
while (1)
{
if(HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)== GPIO_PIN_RESET )
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);
}
}
Can some one help me to make the GPIOA,GPIO_PIN_5 pin high always on the first press of the button and the GPIOA,GPIO_PIN_5 low always at the second press ?
The function will be similar as in the below video https://www.youtube.com/watch?v=zzWzSPdxA0U
Thank you all in advance.
There are several problems with the code. There is no memory function and you are reading the button at max speed.
This is fixed by sleeping for a period of time to allow for human reaction speed and button noise. You also need a variable to store the previous state.
while (1)
{
if(HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)== GPIO_PIN_RESET )
{
static bool state = false;
if(state == false)
{
state = true;
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);
}
else
{
state = false
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);
}
while(HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_13)== GPIO_PIN_RESET){} // wait for button to be released, otherwise it will keep toggling every 500ms
}
delay_ms(500);
}
This is C++ code as it uses bool. int with the values 1 and 0 can be used for C.
What is done is a variable state is declared and kept in heap memory because of the static keyword. (Instead of stack memory which would be destroyed when the scope of the outer if statement is exited) It is initialized to false and then updated when you press the button.
Possible (crude) solution:
#include <stdbool.h>
#define BUTTON_DOWN() (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET)
#define LED(on) HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, (on) ? GPIO_PIN_SET : GPIO_PIN_RESET)
static bool _pressed_before = false;
static bool _led = false;
/* somewhere in main loop */
{
const bool pressed = BUTTON_DOWN();
if (pressed && !_pressed_before) { /* button pressed? */
_led = !_led; /* toggle LED state */
LED(_led);
}
_pressed_before = pressed; /* remember state */
}
Some notes:
Instead of constantly polling the state, you could use an external GPIO interrupt (search for GPIO EXTI). And it is almost always necessary to use hardware debouncing on the button pin (RC filter) and/or use software debouncing to prevent falsely detected edges. - Also: This question is not really STM32 / hardware specific, so you could find more general answers by searching the webs more broadly on these topics.

Can't stop audio playback on iOS with Codename One

My Codename One app features audio playback in the background when the user taps the screen. The audio I use is an mp3. Here is how I use the Media playback :
public static void playSound(boolean stop) {
sound.reset(); // The input stream needs to go back to the beginning
Media myClip = MediaManager.createMedia(sound, "audio/mp3", () -> {
// If there is no order to stop playback, we keep playing when it has completed (looping)
playSound(false);
});
if (!stop) {
myClip.play();
} else {
myClip.cleanup();
}
}
So hen the user taps the screen components change and I pass true to playSound method. On Android the current playback stops not on iOS with an iPhone 4.
Please note that when the app gets minimized (center button pressed) the playback stops (even if I don't call cleanup() on the Media which I do on Android to stop the playback when the app is minimized).
How can I stop the playback on iPhone ?
Any help appreciated,
#Shai pointed me to the right direction so here is the code finally used :
Media myClip = null;
public static void playSound(boolean stop) {
sound.reset(); // The input stream needs to go back to the beginning
/**
* If the media is playing we don't create it
* otherwise we would have several media in the wild
* that could not be stopped
*/
if (myClip == null || !myClip.isPlaying()) {
myClip = MediaManager.createMedia(sound, "audio/mp3", () -> {
// If there is no order to stop playback, we keep playing when it has completed (looping)
playSound(false);
});
}
if (!stop) {
myClip.play();
} else {
myClip.cleanup();
}
}

Why Arduino needs to be restarted after PS2 controller communication in Arduino? And how to to do this via coding?

When I ran the code for a drivetrain and opened serial monitor it was working, but when I powered on Arduino via dc Jack and ran the code. It was not working, because code is needed to restart after connection. I want to know that how can I solve this problem of PS2 communication and run my drivetrain without restart or starting serial monitor.
Code that I uploaded was given in this instructable
http://www.instructables.com/id/Control-anything-with-ps2-controller-and-Arduino-/
I got my answer by experimenting a lot. First thing is that you have to either restart your arduino or configure your pin after connection of ps2 to arduino. This can be done by 2 ways :
1) Restart arduino after connection by code or
2) configure again after connection
1 option you know well, i am discussing 2nd i.e configure :
as you know that you have already configured pins by function ps2x.config_gamepad();
Now you have to reconfigure it after connection of ps2 to arduino, you can use a function called reconfig_gamepad(); after read_gamepad(); in void loop.
my code for holonomic drive train is below find out comments // there are total four commented lines in code. good luck. Hope this will solve your problem also.
#include <PS2X_lib.h> //for v1.6
int dir1=13;
int dir2=11;
int dir3=9;
int dir4=7;
int pwm1=12;
int pwm2=10;
int pwm3=8;
int pwm4=6;
int value_mapped;
/******************************************************************
* set pins connected to PS2 controller:
* - 1e column: original
* - 2e colmun: Stef?
* replace pin numbers by the ones you use
******************************************************************/
#define PS2_DAT 44 //14
#define PS2_CMD 46 //15
#define PS2_SEL 48 //16
#define PS2_CLK 50 //17
/******************************************************************
* select modes of PS2 controller:
* - pressures = analog reading of push-butttons
* - rumble = motor rumbling
* uncomment 1 of the lines for each mode selection
******************************************************************/
//#define pressures true
#define pressures false
//#define rumble true
#define rumble false
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you connect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
void setup(){
Serial.begin(57600);
pinMode(dir1,OUTPUT);
pinMode(dir2,OUTPUT);
pinMode(dir3,OUTPUT);
pinMode(dir4,OUTPUT);
pinMode(pwm1,OUTPUT);
pinMode(pwm2,OUTPUT);
pinMode(pwm3,OUTPUT);
pinMode(pwm4,OUTPUT);
delay(1000); //added delay to give wireless ps2 module some time to startup, before configuring it
//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
if_error_is_found: // <!---- changed here --->
//setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);
if(error == 0){
Serial.print("Found Controller, configured successful ");
Serial.print("pressures = ");
if (pressures)
Serial.println("true ");
else
Serial.println("false");
Serial.print("rumble = ");
if (rumble)
Serial.println("true)");
else
Serial.println("false");
Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
Serial.println("holding L1 or R1 will print out the analog stick values.");
Serial.println("Note: Go to www.billporter.info for updates and to report bugs.");
}
else if(error == 1)
{
Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
goto if_error_is_found; // <!---- changed here --->
}
else if(error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
// Serial.print(ps2x.Analog(1), HEX);
type = ps2x.readType();
switch(type) {
case 0:
Serial.print("Unknown Controller type found ");
break;
case 1:
Serial.print("DualShock Controller found ");
break;
case 2:
Serial.print("GuitarHero Controller found ");
break;
case 3:
Serial.print("Wireless Sony DualShock Controller found ");
break;
}
}
void loop() {
/* You must Read Gamepad to get new values and set vibration values
ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
if you don't enable the rumble, use ps2x.read_gamepad(); with no values
You should call this at least once a second
*/
if(error == 1) //skip loop if no controller found
return;
if(type == 2){ //Guitar Hero Controller
ps2x.read_gamepad(); //read controller
if(ps2x.ButtonPressed(GREEN_FRET))
Serial.println("Green Fret Pressed");
if(ps2x.ButtonPressed(RED_FRET))
Serial.println("Red Fret Pressed");
if(ps2x.ButtonPressed(YELLOW_FRET))
Serial.println("Yellow Fret Pressed");
if(ps2x.ButtonPressed(BLUE_FRET))
Serial.println("Blue Fret Pressed");
if(ps2x.ButtonPressed(ORANGE_FRET))
Serial.println("Orange Fret Pressed");
if(ps2x.ButtonPressed(STAR_POWER))
Serial.println("Star Power Command");
if(ps2x.Button(UP_STRUM)) //will be TRUE as long as button is pressed
Serial.println("Up Strum");
if(ps2x.Button(DOWN_STRUM))
Serial.println("DOWN Strum");
if(ps2x.Button(PSB_START)) //will be TRUE as long as button is pressed
Serial.println("Start is being held");
if(ps2x.Button(PSB_SELECT))
Serial.println("Select is being held");
if(ps2x.Button(ORANGE_FRET)) { // print stick value IF TRUE
Serial.print("Wammy Bar Position:");
Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
}
}
else { //DualShock Controller
ps2x.read_gamepad(); //read controller and set large motor to spin at 'vibrate' speed
ps2x.reconfig_gamepad(); // <!---- changed here --->
if(ps2x.Button(PSB_START)) //will be TRUE as long as button is pressed
Serial.println("Start is being held");
if(ps2x.Button(PSB_SELECT))
Serial.println("Select is being held");
if(ps2x.Button(PSB_PAD_UP)) { //will be TRUE as long as button is pressed
Serial.print("Up held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
}
if(ps2x.Button(PSB_PAD_RIGHT)){
Serial.print("Right held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
}
if(ps2x.Button(PSB_PAD_LEFT)){
Serial.print("LEFT held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
}
if(ps2x.Button(PSB_PAD_DOWN)){
Serial.print("DOWN held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
}
vibrate = ps2x.Analog(PSAB_CROSS); //this will set the large motor vibrate speed based on how hard you press the blue (X) button
if (ps2x.NewButtonState()) { //will be TRUE if any button changes state (on to off, or off to on)
if(ps2x.Button(PSB_L3))
Serial.println("L3 pressed");
if(ps2x.Button(PSB_R3))
Serial.println("R3 pressed");
if(ps2x.Button(PSB_L2))
Serial.println("L2 pressed");
if(ps2x.Button(PSB_R2))
Serial.println("R2 pressed");
if(ps2x.Button(PSB_TRIANGLE))
Serial.println("Triangle pressed");
}
if(ps2x.ButtonPressed(PSB_CIRCLE)) //will be TRUE if button was JUST pressed
Serial.println("Circle just pressed");
if(ps2x.NewButtonState(PSB_CROSS)) //will be TRUE if button was JUST pressed OR released
Serial.println("X just changed");
if(ps2x.ButtonReleased(PSB_SQUARE)) //will be TRUE if button was JUST released
Serial.println("Square just released");
// if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) { //print stick values if either is TRUE
Serial.println("Stick Values:");
Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX
//Forward Direction And BAckward Diretion
if(ps2x.Button(PSB_R1)){
if(ps2x.Analog(PSS_RY)>=0)
{
//Forward Direction
if(ps2x.Analog(PSS_RY)<127)
{
Serial.println("All MOtor Running Forward");
digitalWrite(dir1,LOW);
digitalWrite(dir2,HIGH);
digitalWrite(dir3,HIGH);
digitalWrite(dir4,LOW);
value_mapped=map(ps2x.Analog(PSS_RY),127,0,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm2,value_mapped);
analogWrite(pwm3,value_mapped);
analogWrite(pwm4,value_mapped);
}
//BAckward Direction
if(ps2x.Analog(PSS_RY)>=127)
{
Serial.println("All MOtor Running Backward");
digitalWrite(dir1,HIGH);
digitalWrite(dir2,LOW);
digitalWrite(dir3,LOW);
digitalWrite(dir4,HIGH);
value_mapped=map(ps2x.Analog(PSS_RY),127,255,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm2,value_mapped);
analogWrite(pwm3,value_mapped);
analogWrite(pwm4,value_mapped);
}
}
// LEft OR Right Direction
if(ps2x.Analog(PSS_RX)>=0)
{
//Left diretion
if(ps2x.Analog(PSS_RX)<128)
{
Serial.println("All MOtor Running Left");
digitalWrite(dir1,HIGH);
digitalWrite(dir2,HIGH);
digitalWrite(dir3,LOW);
digitalWrite(dir4,LOW);
value_mapped=map(ps2x.Analog(PSS_RX),128,0,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm2,value_mapped);
analogWrite(pwm3,value_mapped);
analogWrite(pwm4,value_mapped);
}
//Right Direction
if(ps2x.Analog(PSS_RX)>128)
{
Serial.println("All MOtor Running Right");
digitalWrite(dir1,LOW);
digitalWrite(dir2,LOW);
digitalWrite(dir3,HIGH);
digitalWrite(dir4,HIGH);
value_mapped=map(ps2x.Analog(PSS_RX),128,255,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm2,value_mapped);
analogWrite(pwm3,value_mapped);
analogWrite(pwm4,value_mapped);
}
}
//All MOtors Clock
if( (ps2x.Analog(PSS_LX)<128) )
{
Serial.println("CLOCKWISE RUNNING ALL MOTORS");
digitalWrite(dir1,LOW);
digitalWrite(dir2,LOW);
digitalWrite(dir3,LOW);
digitalWrite(dir4,LOW);
value_mapped=map(ps2x.Analog(PSS_LX),128,0,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm2,value_mapped);
analogWrite(pwm3,value_mapped);
analogWrite(pwm4,value_mapped);
}
//All MOtors Anti-CLockwise
if(ps2x.Analog(PSS_LX)>128)
{
Serial.println("CLOCKWISE RUNNING ALL MOTORS");
digitalWrite(dir1,HIGH);
digitalWrite(dir2,HIGH);
digitalWrite(dir3,HIGH);
digitalWrite(dir4,HIGH);
value_mapped=map(ps2x.Analog(PSS_LX),128,255,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm2,value_mapped);
analogWrite(pwm3,value_mapped);
analogWrite(pwm4,value_mapped);
}
}
if(ps2x.Button(PSB_L1)){
if((ps2x.Analog(PSS_LX)>=120) && (ps2x.Analog(PSS_LX)<=128)){
analogWrite(pwm1,0);
analogWrite(pwm3,0);
}
//dIAGONAL L
if(ps2x.Analog(PSS_LX)<120)
{
Serial.println("CLOCKWISE RUNNING ALL MOTORS");
digitalWrite(dir1,LOW);
digitalWrite(dir3,HIGH);
value_mapped=map(ps2x.Analog(PSS_LX),128,0,0,80);
analogWrite(pwm1,value_mapped);
analogWrite(pwm3,value_mapped);
}
//dIAGONAL R
if(ps2x.Analog(PSS_LX)>=128)
{
Serial.println("CLOCKWISE RUNNING ALL MOTORS");
digitalWrite(dir2,HIGH);
digitalWrite(dir4,LOW);
value_mapped=map(ps2x.Analog(PSS_LX),128,255,0,80);
analogWrite(pwm2,value_mapped);
analogWrite(pwm4,value_mapped);
}
}
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
// }
}
delay(50);
}
Here's how I did it.....
void setup()
{
Serial.begin(9600);
// retry logic to avoid a reset after power up
do
{
delay(1000);
error = ps2x.config_gamepad(13, 11, 10, 12, true, true);
if (error == 1)
Serial.println("No controller found, retry in a sec");
} while (error == 1);
if (error == 0)
{
Serial.println("Found Controller, configured successful");
Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
Serial.println("holding L1 or R1 will print out the analog stick values.");
Serial.println("Go to www.billporter.info for updates and to report bugs.");
}
else if (error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if (error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
type = ps2x.readType();
switch (type)
{
case 0:
Serial.println("Unknown Controller type");

JavaFx set volume on MediaPlayer not working

This question has been asked before but to date there is no answer. I have just struck the same problem. I traced into the mediaplayer source and all is well until I get to gstSetVolume in GSTMediaPlayer for which I don't have the source.
At that point the volume value is still correct.
After setting the volume System.out.println(player.getVolume()); reports the correct value (0.0 - 1.0) BUT the volume has not changed. If the slider is set to 0, the audio is muted. Any other value is full volume.
Platform is Netbeans 8.1 on Windows 7 with JavaFX-8 and JDK-8 and the media source is a standard mp4 which works on all tested players (Windows, VLC etc).
Here is the code attached to a MediaView (which works well):
Runnable videoLoop;
PlayListViewController playListViewController;
// Videos are looped here
public void startVideoLoop() {
playerIndex = 0;
videoLoop = () -> {
// Previous player MUST be stopped otherwise it is left
// in the PLAYING state and the next video will not PLAY
if (player != null) {
player.stop();
}
// Point to the next player
if (++playerIndex == videoPlayersList.size()) {
playerIndex = 0;
}
playVideoSequence();
};
playVideoSequence();
}
public void playVideoSequence() {
// If the video options are shown we can update the listview
if (playListViewController != null) {
playListViewController.setListViewItem(playerIndex);
}
player = videoPlayersList.get(playerIndex);
mediaView.setMediaPlayer(player);
player.setOnEndOfMedia(videoLoop);
player.play();
}
A right mouse button press then invokes a 'settings' option. This is a View Controller which is attached to an FXML view. The controller receives a reference to the videoField when it is invoked. Here is the relevant snippet:
private void setHandlers() {
idVolumeSlider.valueProperty().addListener(new ChangeListener() {
#Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
// videoField is a separate class
videoField.setVolume(idVolumeSlider.getValue());
}
});
I'm sorry I cannot supply a 'cut and paste' example, because that would mean a lot of pruning and simplifying of classes to achieve that with the risk of introducing additional problems.