1

我正在尝试通过 rtmp 从浏览器流式传输音频。我为此使用了 flash api。一切都在本地主机上完美运行。当我尝试在专用服务器上录制来自浏览器的声音时,它告诉我,客户端(我)不允许在浏览器中从我的麦克风进行捕获(mic.mutedtrue),但之后我确实允许了第一个请求,设置中仍然允许。任何想法?

    <?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>
4

0 回答 0