Bonjour à tous,
Mon projet actuel a besoin d'accéder au micro et à la caméra de l'utilisateur. J'aimerais donc détecter si j'ai les autorisations nécessaires.
Je me suis donc basé sur cet exemple :
http://help.adobe.com/en_US/FlashPla...xamplesSummary
Afin de vérifier si mon code était valide, j'ai fait un petit projet spécifique, pour tester :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
initialize="init(event)">
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
private var mic:Microphone;
protected function init(event:FlexEvent):void
{
mic = Microphone.getMicrophone();
if (mic != null) {
mic.addEventListener(StatusEvent.STATUS, statusEventHandler);
if (mic.muted) {
Security.showSettings(SecurityPanel.PRIVACY);
}
}
}
private function statusEventHandler(statusEvent:StatusEvent):void {
Alert.show(statusEvent.code, "StatusEvent");
}
]]>
</fx:Script>
</s:Application> |
Ici, j'ai bien le comportement attendu :
- je détecte que je n'ai pas encore l'autorisation d'accéder au micro
- j'affiche la fenêtre de "paramètres"
- je reçois l'event dans mon handler.
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| <?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:ctrl="com.flashphoner.api.communication.*"
xmlns:click2call="com.flashphoner.click2call.views.*"
width="240" height="520" initialize="init()" layout="absolute" verticalScrollPolicy="off" horizontalScrollPolicy="off"
backgroundAlpha="0">
<mx:Style source="styles/style.css"/>
<mx:Script>
<![CDATA[
import com.adobe.cairngorm.control.CairngormEventDispatcher;
import com.flashphoner.Logger;
import com.flashphoner.api.Flash_API;
import com.flashphoner.api.data.PhoneConfig;
import com.flashphoner.api.management.SoundControl;
import com.flashphoner.click2call.APINotifyClick2Call;
import com.flashphoner.click2call.DataClick2Call;
import com.flashphoner.click2call.LabelValue;
import com.flashphoner.click2call.statemachine.CallStateMachineManager;
import com.flashphoner.click2call.statemachine.CallTransitionEvent;
import com.flashphoner.click2call.views.VersionView;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.utils.ObjectUtil;
private static const VERSION_NUMBER:String = "0.9-snapshot";
private var count:int=0;
private var versionView:VersionView;
private var callStateMachine:CallStateMachineManager = new CallStateMachineManager();
private var apiNotify:APINotifyClick2Call = new APINotifyClick2Call();
private var mic:Microphone;
private function init():void
{
Logger.info("Starting click2call - current version : " + VERSION_NUMBER);
DataClick2Call.getInstance().flash_API.addAPINotify(apiNotify);
DataClick2Call.getInstance().phoneButtonLabel = phoneButtonLabel;
DataClick2Call.getInstance().videoButtonLabel = videoButtonLabel;
DataClick2Call.getInstance().videoView = videoView;
//show logger window if debug mode
if (parameters.hasOwnProperty("debug")) {
loggerTextArea.visible = true;
} else {
loggerTextArea.visible = false;
}
if (parameters.hasOwnProperty("contactName")) {
DataClick2Call.getInstance().contactName = parameters.contactName;
DataClick2Call.getInstance().phoneButtonLabel.text = DataClick2Call.getInstance().contactName;
}
if (parameters.hasOwnProperty("enableVideo")) {
var enableVideoString:String = parameters.enableVideo as String;
Logger.info("enableVideo as String value : "+ enableVideoString);
var enableVideo:Boolean = false;
if (enableVideoString == "true") {
enableVideo = true;
}
Logger.info("enableVideo value : "+ enableVideo);
videoButtonLabel.visible = enableVideo;
videoButton.visible = enableVideo;
}
// adding listeners to callEvent
addEventListener(CallTransitionEvent.AUDIO_CLICK, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.CONNECTED, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.RINGING, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.BUSY, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.OK, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.FINISH, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.ERROR, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.DISCONNECTED, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.VIDEO_CHANGED, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.VIDEO_CLICK, callStateMachine.stateEval);
addEventListener(CallTransitionEvent.VIDEO_TIMEOUT, callStateMachine.stateEval);
// test microphone - display security panel if muted
mic = Microphone.getMicrophone();
if (mic != null) {
mic.addEventListener(StatusEvent.STATUS, microphoneStatusEventHandler);
if (mic.muted) {
Security.showSettings(SecurityPanel.PRIVACY);
}
}
}
private function microphoneStatusEventHandler(statusEvent:StatusEvent):void {
Logger.debug("microphoneStatusEventHandler : "+ ObjectUtil.toString(statusEvent));
}
private function onOpenMicrophoneSettingsView():void{
SoundControl.getInstance().getMicrophone().setLoopBack(true);
PopUpManager.addPopUp(DataClick2Call.getInstance().microphoneSettingsView,this);
//PopUpManager.centerPopUp(DataClick2Call.getInstance().microphoneSettingsView);
}
]]>
</mx:Script>
<!-- Grey : [#ababab, #c4c4c4] -->
<mx:Panel width="100%" height="100%" layout="absolute" cornerRadius="0" backgroundAlpha="0">
<click2call:PhoneButton id="phoneButton" x="12" y="59" width="150" height="35" cornerRadius="5"/>
<mx:Label id="phoneButtonLabel" x="12" y="100" width="150" textAlign="center" fontSize="12" visible="true" fontWeight="normal" color="#FFFFFF"/>
<mx:Button x="174" y="59" width="35" height="35" alpha="0.65" borderColor="#C1CFE1"
click="onOpenMicrophoneSettingsView()" cornerRadius="5" fillAlphas="[1.0, 1.0]"
fillColors="[#DEEEFF, #A5CCFF, #B7DBFF, #4A8ACB]" fontSize="10" themeColor="#86A3C1"
toolTip="Mic settings" icon="@Embed(source='/assets/parameters.png')"/>
<click2call:VideoButton id="videoButton" x="12" y="137" width="150" height="35" label="Vidéo" cornerRadius="5" toolTip="Open video window"/>
<mx:Label id="videoButtonLabel" x="12" y="175" width="150" textAlign="center" fontSize="12" visible="true" fontWeight="normal" color="#FFFFFF"/>
<click2call:VideoView id="videoView" visible="false" x="12" y="200"/>
<!-- Logger -->
<mx:TextArea id="loggerTextArea" x="5" y="215" horizontalCenter="true" width="230" height="300" editable="false" verticalScrollPolicy="auto" text="{Logger.log}"/>
</mx:Panel>
</mx:Application> |
J'ai donc repris le code, et je l'ai injecté dans mon projet actuel.
Cependant, dans cette configuration, je ne reçois pas le StatusEvent quand je clique sur la case "autoriser" dans les paramètres.
En utilisant le débuggeur, j'ai vu que :
- sans breakpoint, impossible d'entrer dans microphoneStatusEventHandler.
- quand je met un breakpoint, l'application rentre dans microphoneStatusEventHandler avant même d'afficher le log initial (Logger.info("Starting click2call - current version : " + VERSION_NUMBER)). Tant que le breakpoint reste activé, je reviens toujours dans le handler. Si je le désactive, l'application s'exécute normalement.
Je ne sais pas trop d'où provient ce comportement, donc si quelqu'un a une piste, je suis preneur.
Mon player flash est le 11.0.1.152 , sous windows seven.
Merci d'avance.