android模拟器的音频视频输入
- 格式:ppt
- 大小:1.06 MB
- 文档页数:4
Android模拟器ndroid SDK自带一个移动设备模拟器—它是一个可以运行在你电脑上的虚拟设备. Android模拟器可以让你不需使用物理设备即可预览、开发和测试Android应用程序.Android模拟器能够模拟除了接听和拨打电话外的所有移动设备上的典型功能和行为. 如右图所示, Android模拟器提供了大量的导航和控制键,你可以通过鼠标或键盘点击这些按键来为你的应用程序产生事件. 同时它还有一个屏幕用于显示Android自带应用程序和你自己的应用程序.为了便于模拟和测试应用程序, Android模拟器允许你你的应用程序通过Android平台服务调用其他程序、访问网络、播放音频和视频、保存和**数据、通知用户、渲染图像过渡和场景.Android模拟器同样具有强大的调试能力,例如能够记录内核输出的控制台、模拟程序中断(比如接受短信或打入电话)、模拟数据通道中的延时效果和遗失。
下面的章节将提供关于模拟器的详细信息,以及如何在开发应用程序中使用模拟器。
启动和关闭模拟器要启动Android模拟器,首先进入SDK的tools/文件夹,然后输入emulator或./emulator。
这个操作将初始化Android系统,你将会在屏幕上看到模拟器窗口。
要关闭模拟器,只需要关闭模拟器窗口即可。
操作模拟器你可以通过模拟器的启动选项和控制台命令来控制模拟环境的行为和特性。
一旦模拟器启动,你就可以通过键盘和鼠标来”按” 模拟器的按键,从而操作模拟器。
下面的表格总结了模拟器按键可键盘按键之间的映射关系。
模拟器按键键盘按键后退ESC菜单F1 或 PgUp开始F2 或 PgDn呼叫F3挂断F4—F5, F6 未分配电源按键F7禁用/启用所有网络F8开始跟踪F9 (当且仅当有-trace标记时有效)停止跟踪F10 (当且仅当有-trace标记时有效)主页HOME方向键左/上/右/下小键盘 4/8/6/2方向键中心建小键盘 5调低音量小键盘负号(-)调高音量小键盘加号(+)模拟器启动选项Android模拟器提供了很多启动选项,你可以在启动模拟器时指定,来控制其外观和行为。
Android模拟器的使用1.创建和启动模拟器在Eclipse中,点击左上角的图标,如下:然后弹出对话框如下:上图为安卓模拟器管理器,主要是用来管理你创建的所有的模拟器的,你可以在这里创建模拟器,删除、编辑启动已有模拟器。
点击右上角的Start... 按钮创建模拟器,弹出创建对话框如下:填写模拟器相关参数信息,点击右下角的Create AVD 即可创建成功,创建成功后模拟器就会出现在安卓模拟器管理器中,如果你要启动模拟器,请在安卓模拟器管理器中选中要启动的模拟器,然后点击右边的Start... 按钮,稍后模拟器就会启动。
2.为模拟器设置简体中文界面我们在使用模拟器时,一般刚创建的模拟器的语言设置都是英文的,为了使用方便我们要将模拟器的语言设置成简体中文,方法如下:Home -> setting -> Language & keyboard ->select language然后现在简体中文即可。
3.模拟手机拨打电话和发送短信打电话和发短信需要至少2个模拟器。
注意模拟器标题上的数字“5554,5556,5558” 就是这个模拟器的电话号码。
4.模拟器与真机在使用中的区别模拟器的大部分功能与真机相同,你可以下载QQ,微信等安卓手机软件安装到模拟器上,均可以正常使用。
但是还有一小部分功能与真机有区别。
拟器不具备以下功能:不支持呼叫和接听实际来电;但可以通过控制台模拟电话呼叫(呼入和呼出)不支持USB连接不支持相机/视频捕捉不支持音频输入(捕捉);但支持输出(重放)不支持扩展耳机不能确定连接状态不能确定电池电量水平和交流充电状态不能确定SD卡的插入/弹出不支持蓝牙。
模拟器具备的独特功能:api demo,这个API演示主要是ui部分,各种简单的控件使用技巧在里面都可以找到,dev tools,在dev tools可以获取到一些debug时需要的信息。
Android模拟器是什么如何获取Android模拟器本篇文章小编主要是想和从事Android开发或者是正在参加Android培训的小伙伴来探讨一下,什么是Android模拟器以及如何获取Android模拟器。
我们都知道开发人员在上线前的最后一步就是调试,通过调试来看一下程序是否能正常的运行。
所以今天我们就一起来了解一下Android模拟器。
Android模拟器是什么,如何获取Android模拟器:1、什么是模拟器我们开发Android程序之后,需要使用Android手机环境来运行,以验证我们开发程序的效果。
但是如果用真机来调试程序,会影响开发效率。
为了解决这个问题,Android为我们推出了模拟器。
所谓模拟器,就是指在电脑上模拟Android 系统,可以用这个模拟器来调试并运行开发的Android程序。
开发人员不需要真实的Android手机,通过电脑即可模拟运行一部手机,并开发出手机应用程序。
模拟器给Android开发者在开发和测试上带来了很大的便利。
无论在Windows下还是在Linux下,Android模拟器都可以顺利运行,并且官方提供了Eclipse插件,可将模拟器集成到Eclipse的IDE环境。
当然,也可以从命令行启动Android模拟器。
当然Android模拟器不能完全替代真机,与真机的差异如下。
模拟器不支持呼叫和接听实际来电。
模拟器不支持USB连接。
模拟器不支持相机/视频捕捉。
模拟器不支持音频输入(捕捉)。
模拟器不支持扩展耳机。
模拟器不能确定连接状态。
模拟器不能确定电池电量水平和交流充电状态。
模拟器不能确定SD卡的插入/弹出。
模拟器不支持蓝牙。
获取Android模拟器:获取模拟器的方法非常简单,我们既可以从官方网站(http://developer.Android.corn/)免费下载单独的模拟器,也可以从网络中用搜索关键字的方法获取。
网络中推出了很多版本的Android模拟器,例如,有专门针对游戏玩家的,有专门针对不同手机型号的。
Android中通过Intent 调用图片、视频、音频、录音、拍照1.android中的一个隐藏的类:ContentType,其中定义了android支持的mimetype类型类的路径:com.google.android.mms.ContentType2.Action为Intent.ACTION_GET_CONTENT的Intent可以设置许多参数,如: intent.putExtra("crop", "true");intent.putExtra("outputX", appsWallpaperWidth);intent.putExtra("outputY", apps_wallpaper_height);intent.putExtra("aspectX", appsWallpaperWidth);intent.putExtra("aspectY", apps_wallpaper_height);intent.putExtra("scale", true);intent.putExtra("noFaceDetection", true);intent.putExtra("output", appsWallpaperPath);intent.putExtra("outputFormat", "JPEG");3.使用startActivityForResult方法启动Intent对应的Activity,可以在原Activity的回调方法onActivityResult方法中拿到返回的数据.返回的数据放在第三个参数data(Intnet类型)中.使用getData返回一个Uri,再使用context.getContentResolver().openInputStream(uri);可以拿到一个输入流.//选择图片requestCode 返回的标识Intent intent = new Intent(Intent.ACTION_GET_CONTENT);//"android.intent.action.GET_CONTENT"intent.setType(contentType); //查看类型String IMAGE_UNSPECIFIED = "image/*"; Intent wrapperIntent = Intent.createChooser(intent, null);((Activity) context).startActivityForResult(wrapperIntent, requestCode);//添加音频Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";Intent wrapperIntent = Intent.createChooser(intent, null);((Activity) context).startActivityForResult(wrapperIntent, requestCode);//拍摄视频int durationLimit = getVideoCaptureDurationLimit();//SystemProperties.getInt("ro.media.enc.lprof.duration", 60);Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit); startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);//视频Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";Intent wrapperIntent = Intent.createChooser(intent, null);((Activity) context).startActivityForResult(wrapperIntent, requestCode);//录音Intent intent = new Intent(Intent.ACTION_GET_CONTENT);intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audio/amr"; intent.setClassName("com.android.soundrecorder","com.android.soundrecorder.SoundRecorder");((Activity) context).startActivityForResult(intent, requestCode);//拍照REQUEST_CODE_TAKE_PICTURE 为返回的标识Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//"android.media.action.IMAGE_CAPTURE";intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content://mms/scrapSpace");startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);。
Image of the Android EmulatorThe Android SDK includes a mobile device emulator — a virtual mobile device that runs on your computer. The emulator lets you prototype, develop, and test Android applications without using a physical device.The Android emulator all of the hardware and software features of a typical mobile device, except that it can not receive or place actual phone calls. It provides a variety of navigation and control key s, which you can “press” using your mouse or keyboard to generate events for your application. It also provides a screen in which your application is displayed, together with any other Android applications running.To let you model and test your application more easily, the emulator supports Android Virtual Device (AVD) configurations. AVDs let you specify the Android platform that you want to run on the emulator, as well as the hardware options and emulator skin files tht you want to use. Once your application is running on the emulator, it can use the services of the Android platform to invoke other applications, access the network, play audio and video, store and retrieve data, notify the user, and render graphical transitions and themes.The emulator also includes a variety of debug capabilities, such as a console from which you can log kernel output, simulate application interrupts (such as arriving SMS messages or phone calls), and simulate latency effects and dropouts on the data channel.In this document:1. Overview2. Starting and Stopping the Emulator3. Android Virtual Devices and the Emulator4. Controlling the Emulator5. Emulator Startup Options6. Working with Emulator Disk Images1. Default Images2. Runtime Images: User Data and SD Card3. Temporary Images7. Emulator Networking1. Network Address Space2. Local Networking Limitations3. Using Network Redirections4. Configuring the Emulator‟s DNS Settings5. Using the Emulator with a Proxy6. Interconnecting Emulator Instances7. Sending a Voice Call or SMS to Another Emulator Instance1. Using the Emulator Console1. Port Redirections2. Geo Location Provider Emulation3. Sending Events4. Emulating Device Power Characteristics5. Network Status6. Network Delay Emulation7. Network Speed Emulation8. Telephony Emulation9. SMS Emulation10. VM State11. Emulator Window12. Terminating an Emulator Instance2. Using Emulator Skins3. Running Multiple Instances of the Emulator4. Installing Applications on the Emulator5. SD Card Emulation1. Creating an SD card image using the android tool2. Creating an SD card image using mksdcard3. Copying Files to a Disk Image4. Loading the Disk Image at Emulator Startup6. Troubleshooting Emulator Problems7. Emulator LimitationsOverviewThe Android emulator is a QEMU-based application that provides a virtual ARM mobile device on which you canrun your Android applications. It runs a full Android system stack, down to the kernel level, that includes a set of preinstalled applications (such as the dialer) that you can access from your applications. You can choose what version of the Android system you want to run in the emulator by configuring AVDs, and you can also customize the mobile device skin and key mappings. When launching the emulator and at runtime, you can use a variety of commands and options to control the its behaviors.The Android system image distributed in the SDK contains ARM machine code for the Android Linux kernel, the native libraries, the Dalvik VM, and the various Android package files (such as for for the Android framework and preinstalled applications). The emulator‟s QEMU layers provide dynamic binary translation of the ARM machine code to the OS and processor architecture of your development machine.Adding custom capabilities to the underlying QEMU services, the Android emulator supports many hardware features likely to be found on mobile devices, including:* An ARMv5 CPU and the corresponding memory-management unit (MMU)* A 16-bit LCD display* One or more keyboards (a Qwerty-based keyboard and associated Dpad/Phone buttons)* A sound chip with output and input capabilities* Flash memory partitions (emulated through disk image files on the development machine)* A GSM modem, including a simulated SIM CardThe sections below provide more information about the emulator and how to use it for developing Android applications.Starting and Stopping the EmulatorDuring development and testing of your application, you install and run your application in the Android emulator. You can launch the emulator as a standalone application, from a command line, or you can use it as part of your Eclipse development environment. In either case, you specify the AVD configuration to load and any startup options you want to use, as described in this document.You can run your application on a single instance of the emulator or, depending on your needs, you can start multiple emulator instances and run your application in more than one emulated device. You can use the emulator‟s built-in commands to simulate GSM phone calling or SMS between emulator instances, and you can set up network redirections that allow emulators to send data to one another. For more information, see Telephony Emulation, SMS Emulation, and Emulator NetworkingTo start an instance of the emulator from the command line, change to the tools/ folder of the SDK. Enter emulator command like this:emulator -avdThis initializes the emulator and loads an AVD configuration (see the next section for more information about AVDs). You will see the emulator window appear on your screen.If you are working in Eclipse, the ADT plugin for Eclipse installs your application and starts the emulator automatically, when you run or debug the application. You can specify emulator startup options in the Run/Debug dialog, in the Target tab. When the emulator is running, you can issue console commands as described later in this document.If you are not working in Eclipse, see Installing Applications on the Emulator for information about how to install your application.To stop an emulator instance, just close the emulator‟s window.Android Virtual Devices and the EmulatorTo use the emulator, you first must create one or more AVD configurations. In each configuration, you specify an Android platform to run in the emulator and the set of hardware options and emulator skin you want to use. Then, when you launch the emulator, you specify the AVD configuration that you want to load.To specify the AVD you want to load when starting the emulator, you use the -avd argument, as shown in the previous section.Each AVD functions as an independent device, with its own private storage for user data, SD card, and so on. When you launch the emulator with an AVD configuration, it automatically loads the user data and SD card data from the AVD directory. By default, the emulator stores the user data, SD card data, and cache in the AVD directory.To create and manage AVDs you use the android tool, a command-line utility included in the SDK. For complete information about how to set up AVDs, see Android Virtual Devices.Controlling the EmulatorYou can use emulator startup options and console commands to control the behaviors and characteristics of the emulated environment itself.When the emulator is running, you can interact with the emulated mobile device just as you would an actual mobile device, except that you use your mouse pointer to “touch” the touchscreen and your keyboard keys to“press” the simulated device keys.The table below summarizes the mappings between the emulator keys and and the keys of your keyboard. Emulated Device Key Keyboard KeyHome HOMEMenu (left softkey) F2 or Page-up buttonStar (right softkey) Shift-F2 or Page DownBack ESCCall/dial button F3Hangup/end call button F4Search F5Power button F7Audio volume up button KEYPAD_PLUS, Ctrl-5Audio volume down button KEYPAD_MINUS, Ctrl-F6Camera button Ctrl-KEYPAD_5, Ctrl-F3Switch to previous layout orientation (for example, portrait, landscape) KEYPAD_7, Ctrl-F11Switch to next layout orientation (for example, portrait, landscape) KEYPAD_9, Ctrl-F12Toggle cell networking on/off F8Toggle code profiling F9 (only with -trace startup option)Toggle fullscreen mode Alt-EnterToggle trackball mode F6Enter trackball mode temporarily (while key is pressed) DeleteDPad left/up/right/down KEYPAD_4/8/6/2DPad center click KEYPAD_5Onion alpha increase/decrease KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/)Note that, to use keypad keys, you must first disable NumLock on your development computer.Emulator Startup OptionsThe emulator supports a variety of options that you can specify when launching the emulator, to control its appearance or behavior. Here‟s the command-line usage for launching the emulator with options:emulator -avd [- []] … [-]The table below summarizes the available options.Category Option Description CommentsHelp -help Print a list of all emulator options.-help-all Print help for all startup options.-help-Print help for a specific startup option.-help-debug-tags Print a list of all tags for -debug .-help-disk-images Print help for using emulator disk images.-help-environment Print help for emulator environment variables.-help-keys Print the current mapping of keys.-help-keyset-file Print help for defining a custom key mappings file.-help-virtual-device Print help for Android Virtual Device usage.AVD -avd or@ Required. Specifies the AVD to load for this emulator instance. You must create an AVD configuration before launching the emulator. For information, see Android Virtual Devices.Disk Images -cache Use as the working cache partition image. Optionally, you can specify a path relative to the current working directory. If no cache file is specified, the emulator‟s default behavior is to use a temporary file instead.For more information on disk images, use -help-disk-images.-data Use as the working user-data disk image. Optionally, you can specify a path relative to the current working directory. If -data is not used, the emulator looks for a file named “userdata-qemu.img” in the storage area of the AVD being used (see -avd).-initdata When resetting the user-data image (through -wipe-data), copy the contents of this file to the new user-data disk image. By default, the emulator copies the /userdata.img. Optionally, you can specify a path relative to the current working directory. See also -wipe-data.For more information on disk images, use -help-disk-images.-nocache Start the emulator without a cache partition. See also -cache .-ramdisk Use as the ramdisk image. Default value is /ramdisk.img.Optionally, you can specify a path relative to the current working directory. For more information on disk images,use -help-disk-images.-sdcard Use as the SD card image. Default value is /sdcard.img.Optionally, you can specify a path relative to the current working directory. For more information on disk images, use -help-disk-images.-wipe-data Reset the current user-data disk image (that is, the file specified by -datadir and -data, or the default file). The emulator deletes all data from the user data image file, then copies the contents of the file at -inidata data to the image file before starting. See also -initdata.For more information on disk images, use -help-disk-images.Debug -debug Enable/disable debug messages for the specified debug tags. is a space/comma/column-separated list of debug component names. Use -help-debug-tags to print a list of debug component names that you can use. -debug- Enable/disable debug messages for the specified debug tag. Use -help-debug-tags to print a list of debug component names that you can use in .-debug-no- Disable debug messages for the specified debug tag.-logcat Enable logcat output with given tags. If the environment variable ANDROID_LOG_TAGS is defined and not empty, its value will be used to enable logcat output by default.-shell Create a root shell console on the current terminal. You can use this command even if the adb daemon in the emulated system is broken. Pressing Ctrl-c from the shell stops the emulator instead of the shell.-shell-serial Enable the root shell (as in -shell and specify the QEMU character device to use for communication with the shell. must be a QEMU device type. See the documentation for …-serial dev‟ at /qemu/qemu-doc.html#SEC10 for a list of device types.Here are some examples:* -shell-serial stdio is identical to -shell* -shell-serial tcp::4444,server,nowait lets you communicate with the shell over TCP port 4444* -shell-serial fdpair:3:6 lets a parent process communicate with the shell using fds 3 (in) and 6 (out)* -shell-serial fdpair:0:1 uses the normal stdin and stdout fds, except that QEMU won‟t tty-cook the data.-show-kernel Display kernel messages.-trace Enable code profiling (press F9 to start), written to a specified file.-verbose Enable verbose output. Equivalent to -debug-init.You can define the default verbose output options used by emulator instances in the Android environment variable ANDROID_VERBOSE. Define the options you want to use in a comma-delimited list, specifying only the stem of each option: -debug-.Here‟s an example showing ANDROID_VERBOSE defined with the -debug-init and -debug-modem options: ANDROID_VERBOSE=init,modemFor more information about debug tags, use <-help-debug-tags>.Media -audio Use the specified audio backend.-audio-in Use the specified audio-input backend.-audio-out Use the specified audio-output backend.-noaudio Disable audio support in the current emulator instance.-radio Redirect radio modem interface to a host character device.-useaudio Enable audio support in the current emulator instance. Enabled by default.Network -dns-server Use the specified DNS server(s). The value of must be a comma-separated list of up to 4 DNS server names or IP addresses.-http-proxy Make all TCP connections through a specified HTTP/HTTPS proxy The value of can be one of the following:http://: http://: @:The http:// prefix can be omitted. If the -http-proxy command is not supplied, the emulator looks up the http_proxy environment variable and automatically uses any value matching the format described above.-netdelay Set network latency emulation to . Default value is none. See the table in Network Delay Emulation for supported values.-netfast Shortcut for -netspeed full -netdelay none-netspeed Set network speed emulation to . Default value is full. See the table in Network Speed Emulation for supported values.-port Set the console port number for this emulator instance to . The console port number must be an even integer between 5554 and 5584, inclusive. +1 must also be free and will be reserved for ADB.-report-console Report the assigned console port for this emulator instance to a remote third party before starting the emulation. must use one of these formats:tcp: [,server][,max=] unix: [,server][,max=]Use -help-report-consoleto view more information about this topic.System -cpu-delay Slow down emulated CPU speed by Supported values for are integers between 0 and 1000. Note that the does not correlate to clock speed or other absolute metrics — it simply represents an abstract, relative delay factor applied non-deterministically in the emulator. Effective performance does not always scale in direct relationship with values.-gps Redirect NMEA GPS to character device. Use this command to emulate an NMEA-compatible GPS unit connected to an external character device or socket. The format of must be QEMU-specific serial device specification. See the documentation for ‟serial -dev‟ at /qemu/qemu-doc.html#SEC10.-nojni Disable JNI checks in the Dalvik runtime.-qemu Pass arguments to qemu.-qemu -h Display qemu help.-radio Redirect radio mode to the specified character device. The format of must be QEMU-specific serial device specification. See the documentation for ‟serial -dev‟ at http://www.bellar /qemu/qemu-doc.html#SEC10.-timezone Set the timezone for the emulated device to , instead of the host‟s timezone. must be specified in zoneinfo format. For example:“America/Los_Angeles”“Europe/Paris”-version Display the emulator‟s version number.UI -dpi-device Scale the resolution of the emulator to match the screen size of a physical device. The default value is 165. See also -scale.-no-boot-anim Disable the boot animation during emulator startup. Disabling the boot animation can speed the startup time for the emulator.-no-window Disable the emulator‟s graphical window display.-scale Scale the emulator window. is a number between 0.1 and 3 that represents the desired scaling factor. You can also specify scale as a DPI value if you add the suffi x “dpi” to the scale value. A value of “auto” tells the emulator to select the best window size.-raw-keys Disable Unicode keyboard reverse-mapping.-noskin Don‟t use any emulator skin.-keyset Use the specified keyset file instead of the default. The keyset file defines the list of key bindings between the emulator and the host keyboard. For more information, use -help-keyset to print information about this topic. -onion Use overlay image over screen. No support for JPEG. Only PNG is supported.-onion-alpha Specify onion skin translucency value (as percent). Default is 50.-onion-rotation Specify onion skin rotation. must be one of the values 0, 1, 2, 3.-skin This emulator option is deprecated. Please set skin options using AVDs, rather than by using this emulator option. Using this option may yield unexpected and in some cases misleading results, since the density with which to render the skin may not be defined. AVDs let you associate each skin with a default density and override the default as needed. For more information, see Android Virtual Devices.-skindirThis emulator option is deprecated. See comments for -skin, above.Working with Emulator Disk ImagesThe emulator uses mountable disk images stored on your development machine to simulate flash (or similar) partitions on an actual device. For example, it uses disk image containing an emulator-specific kernel, the Android system, a ramdisk image, and writeable images for user data and simulated SD card.To run properly, the emulator requires access to a specific set of disk image files. By default, the Emulator always looks for the disk images in the private storage area of the AVD in use. If no images exist there when the Emulator is launched, it creates the images in the AVD directory based on default versions stored in the SDK.Note: The default storage location for AVDs is in ~/.android/avd on OS X and Linux, C:\Documents and Settings\\.android\ on Windows XP, and C:\Users\\.android\ on Windows Vista.To let you use alternate or custom versions of the image files, the emulator provides startup options that override the default locations and filenames of the image files. When you use the options, the emulator searches for the image file under the image name or location that you specify; if it can not locate the image, it reverts to using the default names and location.The emulator uses three types of image files: default image files, runtime image files, and temporary image files. The sections below describe how to override the location/name of each type of file.Default ImagesWhen the emulator launches but does not find an existing user data image in the active AVD‟s storage area, it creates a new one from a default version included in the SDK. The default user data image is read-only. The image files are read-only.The emulator provides the -systemstartup option to let you override the location under which the emulator looks for the default user data image.The emulator also provides a startup option that lets you override the name of the default user data image, as described in the table below. When you use the option, the emulator looks in the default directory, or in a custom location (if you specified -system).Name Description Commentsuserdata.img The initial user-data disk image Override using -initdata . Also see -data , below.Runtime Images: User Data and SD CardAt runtime, the emulator reads and writes data on two disk images: a user-data image and (optionally) an SD card image. This emulates the user-data partition and removable storage media on actual device.The emulator provides a default user-data disk image. At startup, the emulator creates the default image as a copy of the system user-data image (user-data.img), described above. The emulator stores the new image with the files of the active AVD.The emulator provides startup options to let you override the actual names and storage locations of the runtime images to load, as described in the table below. When you use one of these options, the emulator looks for the specified file(s) in the current working directory, in the AVD directory, or in a custom location (if you specified a path with the filename).Name Description Commentsuserdata-qemu.img An image to which the emulator writes runtime user-data for a unique user. Override using -data , where is the path the image, relative to the current working directory. If you supply a filename only, the emulator looks for the file in the current working directory. If the file at does not exist, the emulator creates an image from the default userdata.img, stores it under the name you specified, and persists user data to it at shutdown.sdcard.img An image representing an SD card inserted into the emulated device. Override using -sdcard , where is the path the image, relative to the current working directory. If you supply a filename only, the emulator looks for the file in the current working directory.User-Data ImageEach emulator instance uses a writeable user-data image to store user- and session-specific data. For example, it uses the image to store a unique user‟s installed application data, settings, databases, and files.At startup, the emulator attempts to load a user-data image stored during a previous session. It looks for the file in the current working directory, in the AVD directory as described above, and at the custom location/name that you specified at startup.* If it finds a user-data image, it mounts the image and makes it available to the system for reading/writing of user data.* If it does not find one, it creates an image by copying the system user-data image (userdata.img), described above. At device power-off, the system persists the user data to the image, so that it will be available in the next session. Note that the emulator stores the new disk image at the location/name that you specify in -data startup option.Note: Because of the AVD configurations used in the emulator, each emulator instance now gets its own dedicated storage. There is no need to use the -d option to specify an instance-specific storage area.SD CardOptionally, you can create a writeable disk image that the emulator can use to simulate removeable storage in an actual device. For information about how to create an emulated SD card and load it in the emulator, see SD Card EmulationYou can also use the android tool to automatically create an SD Card image for you, when creating an AVD. For more information, see Command-line options for AVDs.Temporary ImagesThe emulator creates two writeable images at startup that it deletes at device power-off. The images are:* A writable copy of the Android system image* The /cache partition imageThe emulator does not permit renaming the temporary system image or persisting it at device power-off.The /cache partition image is initially empty, and is used by the browser to cache downloaded web pages and images. The emulator provides an -cache , which specifies the name of the file at which to persist the /cache image at device power-off. If does not exist, the emulator creates it as an empty file.You can also disable the use of the cache partition by specifying the -nocache option at startup.Emulator NetworkingThe emulator provides versatile networking capabilities that you can use to set up complex modeling and testingenvironments for your application. The sections below introduce the emulator‟s network architecture and capabilities.Network Address SpaceEach instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine‟s network interfaces and settin gs and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.The virtual router for each instance manages the 10.0.2/24 network address space — all addresses managed by the router are in the form of 10.0.2., where is a number. Addresses within this space are pre-allocated by the emulator/router as follows:Network Address Description10.0.2.1 Router/gateway address10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)10.0.2.3 First DNS server10.0.2.4 / 10.0.2.5 / 10.0.2.6 Optional second, third and fourth DNS server (if any)10.0.2.15 The emulated device‟s own netwo rk/ethernet interface127.0.0.1 The emulated device‟s own loopback interfaceNote that the same address assignments are used by all running emulator instances. That means that if you have two instances running concurrently on your machine, each will have its own router and, behind that, each will have an IP address of 10.0.2.15. The instances are isolated by a router and can not see each other on the same network. For information about how to let emulator instances communicate over TCP/UDP, see Connecting Emulator Instances.Also note that the address 127.0.0.1 on your development machine corresponds to the emulator‟s own loopback interface. If you want to access services running on your development machine‟s loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.Finally, note that each emulated device‟s pre-allocated addresses are specific to the Android emulator and will probably be very different on real devices (which are also very likely to be NAT-ed, i.e., behind a router/firewall) Local Networking LimitationsEach emulator instance runs behind a virtual router, but unlike an actual device connected to a physical router, the emulated device doesn‟t have access to a physical network. Instead it runs as part of a normal application on your development machine. This means that it is subject to the same networking limitations as other applications on your machine:* Communication with the emulated device may be blocked by a firewall program running on your machine.* Communication with the emulated device may be blocked by another (physical) firewall/router to which your machine is connected.The emulator‟s virtual router should be able to handle all outbound TCP and UDP connections/messages on behalf of the emulated device, provided your development machine‟s network environment allows it to do so. There are no built-in limitations on port numbers or ranges except the one imposed by your host operating system and network.Depending on the environment, the emulator may not be able to support other protocols (such as ICMP, used for “ping”) might not be supported. Currently, the emulator does not support IGMP or multicast.Using Network RedirectionsTo communicate with an emulator instance behind its virtual router, you need to set up network redirections on the virtual router. Clients can then connect to a specified guest port on the router, while the router directs traffic to/from that port to the emulated device‟s host port.To set up the network redirections, you create a mapping of host and guest ports/addresses on the the emulator instance. There are two ways to set up network redirections: using emulator console commands and using the ADB tool, as described below.Setting up Redirections through the Emulator ConsoleEach emulator instance provides a control console the you can connect to, to issue commands that are specific to that instance. You can use the redir console command to set up redirections as needed for an emulator instance. First, determine the console port number for the target emulator instance. For example, the console port number for the first emulator instance launched is 5554. Next, connect to the console of the target emulator instance, specifying its console port number, as follows:telnet localhost 5554Once connected, use the redir command to work with redirections. To add a redirection, use:.add ::where is either tcp or udp, and and sets the mapping between your own machine and the emulated system,。
基于安卓(Android)系统的声音播放系统0 引言Android一词的本义指“机器人”,同时也是Google于2007年11月5日宣布的基于Linux平台的开源移动终端操作系统的名称,该平台由操作系统、中间件、用户界面和应用软件组成,是首个为移动终端打造的真正开放和完整的移动软件。
随着科技的不断发展,手机不再只是人们日常生活的移动通信工具,而是一个多媒体平台,可提供强大的多媒体功能,越来越多的人喜欢用手机听音乐、看电影。
Android系统内置的音乐播放器基于媒体库对歌曲进行管理,并且不支持歌词的同步显示。
对于部分已经习惯的基于文件浏览器形式播放器的用户,操作起来会有所不便。
对于Android手机操作系统,可以充分利用它丰富的可编程扩展性,开发出新的播放器应用软件。
1 Android平台Android软件开发主要涉及到的相关技术包括Android SDK(开发插件、调试工具包等)、Android系统架构和Android应用程序组件。
1.1 Android SDKAndroid SDK(Software Development Kit)提供了Android平台上使用Java语言进行Android应用开发的API接口和工具。
其中,最重要的工具是Android模拟器和Eclipsel2 的Android开发工具插件,同时SDK也包含了各种在模拟器上用于调试、打包和安装的工具。
Eclipse IDE的Android开发工具插件(AndroidDevelopment Tools Plugin for the Eclipse IDE,ADT)大大扩展了Eclipse集成环境功能,使得生成和调试Android应用程序既容易又迅速。
使用Eclipse,ADT 插件可以加快开发Android应用程序的速度。
Android模拟器是在计算机上运行的一个虚拟移动设备,可以使用模拟器来模拟一个实际的Android运行环境,来设计、调试和测试应用程序。
Android⾳视频开发(三):使⽤AudioTrack播放PCM⾳频⼀、AudioTrack 基本使⽤AudioTrack 类可以完成Android平台上⾳频数据的输出任务。
AudioTrack有两种数据加载模式(MODE_STREAM和MODE_STATIC),对应的是数据加载模式和⾳频流类型,对应着两种完全不同的使⽤场景。
MODE_STREAM:在这种模式下,通过write⼀次次把⾳频数据写到AudioTrack中。
这和平时通过write系统调⽤往⽂件中写数据类似,但这种⼯作⽅式每次都需要把数据从⽤户提供的Buffer中拷贝到AudioTrack内部的Buffer中,这在⼀定程度上会使引⼊延时。
为解决这⼀问题,AudioTrack就引⼊了第⼆种模式。
MODE_STATIC:这种模式下,在play之前只需要把所有数据通过⼀次write调⽤传递到AudioTrack中的内部缓冲区,后续就不必再传递数据了。
这种模式适⽤于像铃声这种内存占⽤量较⼩,延时要求较⾼的⽂件。
但它也有⼀个缺点,就是⼀次write的数据不能太多,否则系统⽆法分配⾜够的内存来存储全部数据。
1.1 MODE_STATIC模式MODE_STATIC模式输出⾳频的⽅式如下(注意:如果采⽤STATIC模式,须先调⽤write写数据,然后再调⽤play。
):public class AudioTrackPlayerDemoActivity extends Activity implementsOnClickListener {private static final String TAG = "AudioTrackPlayerDemoActivity";private Button button;private byte[] audioData;private AudioTrack audioTrack;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);super.setContentView(yout.main);this.button = (Button) super.findViewById(R.id.play);this.button.setOnClickListener(this);this.button.setEnabled(false);new AsyncTask<Void, Void, Void>() {@Overrideprotected Void doInBackground(Void... params) {try {InputStream in = getResources().openRawResource(R.raw.ding);try {ByteArrayOutputStream out = new ByteArrayOutputStream(264848);for (int b; (b = in.read()) != -1;) {out.write(b);}Log.d(TAG, "Got the data");audioData = out.toByteArray();} finally {in.close();}} catch (IOException e) {Log.wtf(TAG, "Failed to read", e);}return null;}@Overrideprotected void onPostExecute(Void v) {Log.d(TAG, "Creating track...");button.setEnabled(true);Log.d(TAG, "Enabled button");}}.execute();}public void onClick(View view) {this.button.setEnabled(false);this.releaseAudioTrack();this.audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 44100,AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT,audioData.length, AudioTrack.MODE_STATIC);Log.d(TAG, "Writing audio data...");this.audioTrack.write(audioData, 0, audioData.length);Log.d(TAG, "Starting playback");audioTrack.play();Log.d(TAG, "Playing");this.button.setEnabled(true);}private void releaseAudioTrack() {if (this.audioTrack != null) {Log.d(TAG, "Stopping");audioTrack.stop();Log.d(TAG, "Releasing");audioTrack.release();Log.d(TAG, "Nulling");}}public void onPause() {super.onPause();this.releaseAudioTrack();}}1.2 MODE_STREAM模式MODE_STREAM 模式输出⾳频的⽅式如下:byte[] tempBuffer = new byte[bufferSize];int readCount = 0;while (dis.available() > 0) {readCount = dis.read(tempBuffer);if (readCount == AudioTrack.ERROR_INVALID_OPERATION || readCount == AudioTrack.ERROR_BAD_VALUE) {continue;}if (readCount != 0 && readCount != -1) {audioTrack.play();audioTrack.write(tempBuffer, 0, readCount);}}⼆、AudioTrack 详解2.1 ⾳频流的类型在AudioTrack构造函数中,会接触到AudioManager.STREAM_MUSIC这个参数。
Android⾳频采集——MediaRecord(编码后录影⽂件)、AudioRecord。
⾳频简介常见的⾳频编解码的类型:AAC OPUS MP3 AMR Ogg PCMAAC: ⾼级⾳频编码对应 .m4a(audio/m4a)或者.3pg(audio/3gpp)⽂件 HEAAC:⾼级AAC,使⽤的⽐较多。
OPUS:有损声⾳编码的格式,由互联⽹⼯程任务组(IETF)进来开发,适⽤于⽹络上的实时声⾳传输,如:语⾳通话MP3: 使⽤的最⼴泛的⾳频编解码器对应 .mp3(audio/mp3) 各种⾳乐⽹站⼀般⽤这种。
AMR:⾃适应多速率⾳频编解码器,⼀般⽤于语⾳呼叫程序。
Ogg:开发的⽆专利的⾳频编解码器,其质量可与商业的和⼿专利保护的MP3以及AAC编解码相媲美。
PCM :原始⾳频,在平台上由audio record直接录⽤下来的,未经过编码的。
视频直播,语⾳通话中⼀般使⽤AAC或者OPUS ,如果对声⾳要进⾏处理就需要使⽤PCM原始⾳频加⼯处理,然后再进⾏编码.Android⾳频采集(捕获)android平台上的⾳频采集⼀般就三种:1.利⽤android内置的应⽤程序 2.使⽤MediaRecorder进⾏⾳频捕获 3.使⽤AudioRecord进⾏⾳频捕获。
此3种⽅式的灵活性逐渐增⼤,相应的所需要做的⼯作也逐渐增多。
⼀、Android 内置的应⽤程序。
[java]1. Intent intent=new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);2. startActivityForResult(intent,0); //通过startActivityForResult获取⾳频录制的结果的路径这种⽅式灵活度最差,⼀般就是做着演⽰下,开发中基本不⽤这种⽅案。
⼆、使⽤MediaRecorder进⾏⾳频的捕获。
这个是录影视频和⾳频分别编码后保存成⼀个⽂件,单独⾳频也可以,不过是编码后的数据这种⽅案相较于调⽤系统内置的⽤⽤程序,灵活度要⾼很多,便于开发者在UI界⾯上布局,⽽且系统封装的很好,便于使⽤,唯⼀的缺点是使⽤它录下来的⾳频是经过编码的,没有办法的得到原始的⾳频。