我正在尝试通过rtmp从浏览器传输音频。我使用flash api。在localhost上一切都很完美。当我试图在专用服务器上记录来自浏览器的声音时,它告诉我,客户端(我)不允许捕获( microphone.muted true )我的麦克风在浏览器中,但我确实在第一次请求后允许它,它仍然允许在设置中。有什么想法吗?
<?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="500" minHeight="350" creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
private var streamer:String;
private var file:String;
private var microphone:Microphone;
private var connection:NetConnection;
private var stream:NetStream;
private var h264Settings:H264VideoStreamSettings;
private function toggleFeedListener():void {
if(toggleFeed.label == 'Start Feed') {
toggleFeed.label = 'Stop Feed';
stream.publish(file, 'live');
} else {
toggleFeed.label = 'Start Feed';
stream.close();
}
}
private function stopStream():void {
if(toggleFeed.label != 'Start Feed') {
toggleFeed.label = 'Start Feed';
stream.close();
}
}
private function startStream():void {
if(toggleFeed.label == 'Start Feed') {
toggleFeed.label = 'Stop Feed';
stream.publish(file, 'live');
}
}
private function getActivityLevel():int {
return microphone.activityLevel;
}
private function initListeners():void {
ExternalInterface.addCallback("toggleFeedListener", toggleFeedListener);
ExternalInterface.addCallback("startStream", startStream);
ExternalInterface.addCallback("stopStream", stopStream);
ExternalInterface.addCallback("getActivityLevel", getActivityLevel);
}
private function log(message:String):void
{
trace (message);
if (ExternalInterface.available)
{
ExternalInterface.call('console.log', message);
}
}
private function netStatusHander(event:NetStatusEvent):void {
switch(event.info.code) {
case 'NetConnection.Connect.Success':
stream = new NetStream(connection);
stream.attachAudio(microphone);
h264Settings = new H264VideoStreamSettings();
h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_1_2);
stream.videoStreamSettings = h264Settings;
break;
}
}
private function init():void {
streamer = FlexGlobals.topLevelApplication.parameters.streamer;
file = FlexGlobals.topLevelApplication.parameters.file;
if(file == null) {
Alert.show('Missing flashvars: file');
return;
}
if(streamer == null) {
Alert.show('Missing flashvars: streamer');
return;
}
microphone = Microphone.getEnhancedMicrophone();
log (String(microphone.muted));
log (microphone.name);
log (String(microphone.index));
initListeners();
microphone.setSilenceLevel(0);
//microphone.codec = "Speex";
microphone.encodeQuality = 10; // 0 - 10
connection = new NetConnection();
connection.connect(streamer);
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHander);
}
]]>
</fx:Script>
<s:Panel x="0" y="0" width="100%" height="100%" title="RTMP Publisher">
<s:controlBarContent>
<s:Button label="Start Feed" id="toggleFeed"></s:Button>
<s:Spacer width="100%" height="100%"/>
</s:controlBarContent>
</s:Panel>
</s:Application>