大家好我正在使用Flash Builder 4.6中的移动相机应用程序。
我的问题是,我可以让摄像头使用网络摄像头,但不能使用移动摄像头进行部署。我正在使用AIR尝试流式传输。
这就是我调用按钮的方式:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Capture">
<!-- Button event script -->
<fx:Script>
<![CDATA[
{
//Bring in the actionscript
import views.CoolVideo;
//The button handler
private function button1_clickHandler(event:MouseEvent):void
{
//Calling the actionScript function
new CoolVideo();
}
}
]]>
</fx:Script>
<!-- Basic structure of the app page -->
<s:VGroup width="100%" height="100%" verticalAlign="middle" horizontalAlign="center">
<!-- Label on the screen -->
<s:Label text="Capture page(current)"/>
<!-- Button to change between screens -->
<s:Button label="Capture" click="button1_clickHandler(event)" styleName="next"/>
<s:Button label="Back" click="navigator.pushView(app3HomeView)" styleName="next"/>
<!--<s:Image id="img" height="649" y="124" width="460" x="10"/> -->
</s:VGroup>
</s:View>
在这里,我使用按钮处理程序button1_clickHandler
调用我的动作脚本,该处理程序转到动作脚本:
package views
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.media.Camera;
import flash.media.CameraUI;
import flash.media.H264Level;
import flash.media.H264Profile;
import flash.media.H264VideoStreamSettings;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFormat;
public class CoolVideo extends Sprite
{
//All the Stuff we need
private var metaText:TextField = new TextField();
private var vid_outDescription:TextField = new TextField();
private var vid_inDescription:TextField = new TextField();
private var metaTextTitle:TextField = new TextField();
//the connection will be used to link to server
private var nc:NetConnection;
//net stream is the data flow
private var ns_out:NetStream;
//the camera, get camera looks for an available camera returns null if not one available
private var cam:Camera = Camera.getCamera();
//this will be the video streamed to the server
private var vid_out:Video;
//Class constructor
public function CoolVideo()
{
//Call initConnection()
initConnection();
}
//Called from class constructor, this function establishes a new NetConnection and listens for its status
private function initConnection():void
{
//instantiate netConnection
nc = new NetConnection();
//The on status event is where all the streaming will go on
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
//make net Connection to the server
nc.connect("rtmp://192.168.200.233/livepkgr/_definst_/");
//Step 7: Tell the NetConnection where the server should invoke callback methods
nc.client=this;
//Instantiate the vid_out variable
vid_out = new Video();
}
//It's a best practice to always check for a successful NetConnection
protected function onNetStatus(event:NetStatusEvent):void
{
//Step 8: Trace the value of event.info.code
trace(event.info.code);
/*Step 9: Check for a successful NetConnection, and if successful
call publishCamera()*/
if(event.info.code == "NetConnection.Connect.Success")
{
publishCamera();
}
}
//The encoding settings are set on the publishing stream
protected function publishCamera():void
{
//Step 12: Instantiate the ns_out NetStream
ns_out = new NetStream(nc);
//Step 13: Attach the camera to the outgoing NetStream
ns_out.attachCamera(cam);
//Step 14: Define a local variable named h264Settings of type H264VideoStreamSettings
var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings();
//Step 15: Set encoding profile and level on h264Settings
h264Settings.setProfileLevel( H264Profile.BASELINE, H264Level.LEVEL_3_1 )
//Step 16: Set the bitrate and quality settings on the Camera object
cam.setQuality( 90000, 90 );
//Step 17: Set the video's height, width, fps, and whether it should maintain its capture size
cam.setMode( 320, 240, 30, true );
//Step 18: Set the keyframe interval
cam.setKeyFrameInterval( 15 );
//Step 19: Set the outgoing video's compression settings based on h264Settings
ns_out.videoStreamSettings = h264Settings;
//Step 20: Publish the outgoing stream
ns_out.publish( "livestream?adbe-live-event=liveevent" );
}
//Step 11: Un-comment this necessary callback function that checks bandwith (remains empty in this case)
public function onBWDone():void
{
}
}
}
如果有人能够了解为什么它不能在移动摄像头上运行,而是在网络摄像头上做得很好甚至可以指向正确的方向
答案 0 :(得分:1)
要在Android中访问设备相机,您需要在<uses-permision>
根目录下的appManifest.xml
文件的<android>
部分中提出请求
EG:
<android>
<colorDepth>16bit</colorDepth>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.CAMERA"/>
</manifest>
]]></manifestAdditions>
</android>
答案 1 :(得分:0)
仔细检查您的所有权限,就像它在仿真环境中工作一样,它几乎就是它的必要条件。