- 浏览: 361890 次
- 性别:
- 来自: 南京
文章分类
最新评论
-
nglxl:
点赞啊,必须点赞!!深度好文,解决了困扰我多年的疑惑。
tcp 长连接与短连接 -
cofftech:
opengl源码http://www.eyesourcecod ...
OPenGL ES 关键API小结 -
mail_j:
不是很好用,很多情况都不能处理 1、没有区分关键字的大小写2、 ...
Java解析sql语句,分析出调用到的所有表 -
a455642158:
就算监听到变成了cmwap还不行,还得监听网络连接状态Stat ...
android APN切换cmwap实现 -
xuhl1022:
看了您的android 4篇 浏览器二次开发,感触颇深,写的很 ...
Android浏览器Browser二次开发(四)浏览器中的APN切换
Audio and Video
Audio/Video quickview
Audio playback and record
Video playback
Handles data from raw resources, files, streams
Built-in codecs for a variety of media. See Android Supported Media Formats
Key classes
MediaPlayer (all available formats)
MediaRecorder (all available formats)
JetPlayer (playback, JET content)
SoundPool (sound management)
In this document
Audio and Video Playback
Playing from a Raw Resource
Playing from a File or Stream
Playing JET Content
Audio Capture
See also
Data Storage
JetCreator User Manual
The Android platform offers built-in encoding/decoding for a variety of common media types, so that you can easily integrate audio, video, and images into your applications. Accessing the platform's media capabilities is fairly straightforward — you do so using the same intents and activities mechanism that the rest of Android uses.
Android lets you play audio and video from several types of data sources. You can play audio or video from media files stored in the application's resources (raw resources), from standalone files in the filesystem, or from a data stream arriving over a network connection. To play audio or video from your application, use the MediaPlayer class.
The platform also lets you record audio and video, where supported by the mobile device hardware. To record audio or video, use the MediaRecorder class. Note that the emulator doesn't have hardware to capture audio or video, but actual mobile devices are likely to provide these capabilities, accessible through the MediaRecorder class.
For a list of media formats for which Android offers built-in support, see the Android Media Formats appendix.
Audio and Video Playback
Media can be played from anywhere: from a raw resource, from a file from the system, or from an available network (URL).
You can play back the audio data only to the standard output device; currently, that is the mobile device speaker or Bluetooth headset. You cannot play sound files in the conversation audio.
Playing from a Raw Resource
Perhaps the most common thing to want to do is play back media (notably sound) within your own applications. Doing this is easy:
Put the sound (or other media resource) file into the res/raw folder of your project, where the Eclipse plugin (or aapt) will find it and make it into a resource that can be referenced from your R class
Create an instance of MediaPlayer, referencing that resource using MediaPlayer.create, and then call start() on the instance:
MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);
mp.start();To stop playback, call stop(). If you wish to later replay the media, then you must reset() and prepare() the MediaPlayer object before calling start() again. (create() calls prepare() the first time.)
To pause playback, call pause(). Resume playback from where you paused with start().
Playing from a File or Stream
You can play back media files from the filesystem or a web URL:
Create an instance of the MediaPlayer using new
Call setDataSource() with a String containing the path (local filesystem or URL) to the file you want to play
First prepare() then start() on the instance:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();stop() and pause() work the same as discussed above.
Note: It is possible that mp could be null, so good code should null check after the new. Also, IllegalArgumentException and IOException either need to be caught or passed on when using setDataSource(), since the file you are referencing may not exist.
Note: If you're passing a URL to an online media file, the file must be capable of progressive download.
Playing JET content
The Android platform includes a JET engine that lets you add interactive playback of JET audio content in your applications. You can create JET content for interactive playback using the JetCreator authoring application that ships with the SDK. To play and manage JET content from your application, use the JetPlayer class.
For a description of JET concepts and instructions on how to use the JetCreator authoring tool, see the JetCreator User Manual. The tool is available fully-featured on the OS X and Windows platforms and the Linux version supports all the content creation features, but not the auditioning of the imported assets.
Here's an example of how to set up JET playback from a .jet file stored on the SD card:
JetPlayer myJet = JetPlayer.getJetPlayer();
myJet.loadJetFile("/sdcard/level1.jet");
byte segmentId = 0;
// queue segment 5, repeat once, use General MIDI, transpose by -1 octave
myJet.queueJetSegment(5, -1, 1, -1, 0, segmentId++);
// queue segment 2
myJet.queueJetSegment(2, -1, 0, 0, 0, segmentId++);
myJet.play();The SDK includes an example application — JetBoy — that shows how to use JetPlayer to create an interactive music soundtrack in your game. It also illustrates how to use JET events to synchronize music and game logic. The application is located at <sdk>/platforms/android-1.5/samples/JetBoy.
Audio Capture
Audio capture from the device is a bit more complicated than audio/video playback, but still fairly simple:
Create a new instance of android.media.MediaRecorder using new
Create a new instance of android.content.ContentValues and put in some standard properties like TITLE, TIMESTAMP, and the all important MIME_TYPE
Create a file path for the data to go to (you can use android.content.ContentResolver to create an entry in the Content database and get it to assign a path automatically which you can then use)
Set the audio source using MediaRecorder.setAudioSource(). You will probably want to use MediaRecorder.AudioSource.MIC
Set output file format using MediaRecorder.setOutputFormat()
Set the audio encoder using MediaRecorder.setAudioEncoder()
Call prepare() on the MediaRecorder instance.
To start audio capture, call start().
To stop audio capture, call stop().
When you are done with the MediaRecorder instance, call release() on it.
Example: Audio Capture Setup and Start
The example below illustrates how to set up, then start audio capture.
recorder = new MediaRecorder();
ContentValues values = new ContentValues(3);
values.put(MediaStore.MediaColumns.TITLE, SOME_NAME_HERE);
values.put(MediaStore.MediaColumns.TIMESTAMP, System.currentTimeMillis());
values.put(MediaStore.MediaColumns.MIME_TYPE, recorder.getMimeContentType());
ContentResolver contentResolver = new ContentResolver();
Uri base = MediaStore.Audio.INTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
if (newUri == null) {
// need to handle exception here - we were not able to create a new
// content entry
}
String path = contentResolver.getDataFilePath(newUri);
// could use setPreviewDisplay() to display a preview to suitable View here
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();Stop Recording
Based on the example above, here's how you would stop audio capture.
recorder.stop();
recorder.release();</sdk>
发表评论
-
基于Java NIO的手机答题游戏开发
2014-03-31 17:59 1788先上个游戏截图: 豌豆荚地址: http://apps.w ... -
enable android deviceconnection under linux
2013-04-24 15:45 1005开发环境搭建完毕,Eclipse,Java,ADT都已经折腾 ... -
set CCache for building android source code
2013-04-24 15:14 1192Setting up ccache You can opti ... -
android 源码下载403 forbidden, 406 not acceptable 错误
2013-04-24 08:46 2454解决方法 1. 浏览器登录https://android.g ... -
ubuntu11.10 编译android4.0 错处
2013-04-08 21:45 1227今天使用ubuntu11.10编译android4.0出现以下 ... -
常用WebService列表
2013-01-31 23:22 2642快递查询接口 http://webservice.36wu.c ... -
startActivityForResult 无响应问题
2013-01-24 13:57 3861今天开发遇到了个问题, 就是从一个Activity中使用sta ... -
Android中仿新浪微博刷新列表
2012-11-22 17:35 7346大家看到新浪微博中的列表往下拉的时候, 头部出现正在刷新,然后 ... -
Grid调整间距
2012-09-29 08:52 1750今天使用GridView, 发现点中某一Item时选中部分的背 ... -
android gallery和Animation组合使用, 看美女美图
2012-09-11 21:01 4452今天主要探究Gallery和Animation的使用。 制作一 ... -
Android执行 shell command
2012-03-24 17:00 7266Android执行shell命令 一、方法 1. /* ... -
BBBBBB111
2012-03-23 11:42 10陈波: 本周:代码review,解决findbugs中bug以 ... -
MonkeyTestError
2012-03-21 10:15 903-20 21:36:42.439 W/dalvikvm( ... -
INSTALL_FAILED_OLDER_SDK ERROR
2012-03-12 15:52 4474Install APK with adb: $ platfo ... -
4.0源码编译问题
2012-03-07 17:12 31581、fatal error: GL/glx.h: No suc ... -
4.0 编译apk中无classes.dex
2012-03-07 17:11 3968下载完android 4.0代码,模拟器里面的gallery不 ... -
Android 4.0源码编译错误
2012-03-05 10:19 2582UNEXPECTED TOP-LEVEL EXCEPTION: ... -
AndroidLockScreenDemo
2012-02-18 15:54 998锁屏解锁的成功案例。 -
G14 root权限获取
2012-02-13 23:36 2870HTC G14 ROOT权限获取后就能删除系统自带的程序,相信 ... -
锁屏d ds
2011-12-15 00:49 908private final IDevicePolicyMana ...
相关推荐
它支持多种平台,包括iOS、Android以及其他基于Unix的操作系统,这得益于其跨平台的设计。项目通过提供API接口,使得开发者能够轻松集成到自己的应用中,进行直播流的创建、编码、传输和播放。 二、关键特性 1. **...
Recording and playing audio and video Using hardware APIs available on Android devices Interacting with other devices via SMS, web browsing, and social networkingStoring data efficiently with SQLite...
9. 第9章“Using Multimedia—Audio, Video, and the Camera”致力于多媒体技术的使用,包括音频播放、视频播放和摄像头控制。 10. 第10章“Talking to Other Applications and Libraries”讨论了应用程序之间的...
Recording and playing audio and video Using hardware APIs available on Android devices Interacting with other devices via SMS, web browsing, and social networkingStoring data efficiently with SQLite ...
It has been tested with Android MediaCodec encoder to send H264 (avc) video and with Android MediaRecorder to send AAC audio via RTMP to a server. RFCs This implementation uses the RTMP 3 protocol ...
content providers and intents are also covered, as are touch screen handling, gesture recognition, camera access and the playback and recording of both video and audio. This edition of the book also ...
5. **VideoView and MediaPlayer**: 这两个是Android SDK中为开发者提供的视频播放接口。VideoView是UI组件,可以直接在布局中插入,用于播放视频。MediaPlayer是一个更底层的API,允许更复杂的控制和自定义。在`...
More advanced topics such as intents are also covered, as are touch screen handling, gesture recognition, camera access and the playback and recording of both video and audio. This edition of the book...
Android FFmpeg 音视频开发极简教程An Android FFmpeg audio and video development tutorial.编译环境: Android Studio 4.1+ ,NDK r21展示图1展示图2Android FFmpeg 音视频开发系列连载FFmpeg 开发(06):FFmpeg ...
Jitsi for Android is an Android port of the Jitsi project: The most feature-rich communicator with support for encrypted audio/video, chat and presence over SIP and XMPP. Usage with IntelliJ Make ...
A demo of record audio and video about Android 一个在 Android 上实现录像和录音功能的小例子。 GitHub 地址:https://github.com/Werb/MediaUtils 也可直接点击下载体验 Android 的 MediaRecorder 相信用过的...
Fully updated for Android Studio 3.0 and Android 8, the goal of this book is ...recording of both video and audio. This edition of the book also covers printing, transitions and cloud-based file storage.
Hardware-Accelerated Audio and Video Conclusion Chapter 15 : Your Device and Others RTMFP UDP P2P Over a Local Network P2P Over a Remote Network Arduino and Physical Computing Conclusion Chapter 16 : ...
CHAPTER 11 Audio, Video, and Using the Camera 363 CHAPTER 12 Telephony and SMS. 389 CHAPTER 13 Bluetooth, Networks, and Wi-Fi 425 CHAPTER 14 Sensors 457 CHAPTER 15 Advanced Android Development...
Hardware-Accelerated Audio and Video Conclusion Chapter 15 : Your Device and Others RTMFP UDP P2P Over a Local Network P2P Over a Remote Network Arduino and Physical Computing Conclusion Chapter 16 : ...