MediaPlayer (all available formats)MediaRecorder (all available formats)JetPlayer (playback, JET content)SoundPool (sound management)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.
안드로이드 플랫폼은 다양한 일반적인 미디어 타입에 대한 내장된built-in 인코딩/디코딩을 제공하며, 이로써 여러분은 쉽게 오디오, 비디오, 이미지를 여러분의 애플리케이션에 통합할 수 있다. 플랫폼의 미디어 기능에 액세스하는 것은 꽤 수월하다 ? 여러분은 인텐트와 액티비티 메커니즘을 사용해서 그렇게 할 수 있으며, 이 메커니즘은 안드로이드의 나머지 부분들에서도 사용된다.
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.
안드로이드는 여러분으로 하여금 여러 유형의 데이터 소스로부터 오디오와 비디오를 재생할 수 있도록 한다. 여러분은 애플리케이션 리소스들(raw resources)에 저장된 미디어 파일들, 파일 시스템에 있는 독립된 파일들, 혹은 네트워크 커넥션을 통해 도착하는 데이터 스트림으로부터 오디오와 비디오를 재생할 수 있다. 애플리케이션에서 오디오와 비디오를 재생하려면 미디어플레이어MediaPlayer 클래스를 사용하라.
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.
플랫폼은 여러분으로 하여금 오디오와 비디오를 녹음(녹화)할 수 있도록 하며, 이것은 모바일 디바이스 하드웨어에 의해 지원된다. 오디오와 비디오를 녹음(녹화)하려면 미디어레코더MediaRecorder 클래스를 사용하라. 에뮬레이터는 오디오와 비디오를 캡쳐하는 하드웨어를 가지고 있지 않지 않다는 것에 유의하라. 하지만 실제 모바일 디바이스는 미디어레코더MediaRecorder를 통해 접근할 수 있는 이러한 기능들을 여러분에게 제공할 것이다.
For a list of media formats for which Android offers built-in support, see the Android Media Formats appendix.
안드로이드가 내장된built-in 지원을 제공하는 미디어 포맷 리스트에 대해서는 이후에 나오는 안드로이드 지원 미디어 포맷을 보라.
Media can be played from anywhere: from a raw resource, from a file from the system, or from an available network (URL).
미디어는 원시 리소스, 시스템 내의 파일, 또는 사용 가능한 네트워크(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.
여러분은 표준 출력 디바이스로만 오디오 데이터를 재생할 수 있다; 현재 그 디바이스는 모바일 디바이스 스피커 또는 블루투스 헤드셋이다. 여러분은 대화형 오디오conversation audio에서 사운드 파일을 재생할 수 없다.
Perhaps the most common thing to want to do is play back media (notably sound) within your own applications. Doing this is easy:
아마도 수행하길 원하는 가장 일반적으로 것은 여러분의 애플리케이션에서 미디어(특히 사운드)를 재생하는 것일 것이다. 이것을 하는 것은 쉽다.
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 classMediaPlayer, 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.)
재생을 중지하려면 stop()을 호출하라. 만약 여러분이 나중에 그 미디어를 다시 재생하고자 한다면, 여러분은 start()를 다시 호출하기 전에 MediaPlayer 오브젝트를 reset()하고 prepare() 해야만 한다(create()는 최초 시점에 prepare()를 호출한다).
To pause playback, call pause().
Resume playback from where you paused with
start().
재생을 일시 정지하기 위해서는 pause()를 호출하라. 여러분은 일시 정지한 곳에서 start()를 사용해서 재생을 재개할 수 있다.
You can play back media files from the filesystem or a web URL:
여러분은 파일 시스템 또는 웹 URL로부터 미디어 파일을 재생할 수 있다.
MediaPlayer using newsetDataSource()
with a String containing the path (local filesystem or URL)
to the file you want to playprepare() 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.
stop()과 pause()는 위에서 논의된 것과 같이 동작한다.
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: mp가 널null 값이 되는 것이 가능하다. 그러므로 좋은 코드는 new 이후에 널null 체크를 해야 한다. 또한 여러분이 레퍼런스하는 파일이 존재하지 않을 수도 있기 때문에, setDataSource()를 사용할 때 IllegalArgumentException과 IOException이 캐치catch되거나 전달될 필요가 있다.
Note: If you're passing a URL to an online media file, the file must be capable of progressive download.
Note: 여러분이 온라인 미디어 파일에 대한 URL을 전달한다면, 그 파일은 프로그레시브progressive 다운로드가 지원되어야 한다.
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.
안드로이드 플랫폼은 여러분의 애플리케이션에 인터랙티브 제트JET 오디오 컨텐트 재생을 추가하게 해주는 제트JET 엔진을 포함하고 있다. 여러분은 SDK에 함께 포함되어 있는 JetCreator 제작authoring 애플리케이션을 사용해서 인터랙티브 재생을 위한 제트JET 컨텐트를 생성할 수 있다. 여러분의 애플리케이션부터 제트JET 컨텐트를 재생하고 관리하기 위해서는, JetPlayer 클래스를 사용하라.
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.
제트JET의 개념과 JetCreator 제작authoring 도구 사용법에 대한 명령어 설명에 대해서는, JetCreator 사용자 메뉴얼을 보라. JetCreator 도구는 OS X와 윈도우 플랫폼 상에서 모든 기능을 제공하며, 리눅스 버전에서 모든 컨텐트 생성 기능들을 지원하지만 임포드import된 에셋들assets의 오디션닝은 지원하지 않는다.
Here's an example of how to set up JET playback from a .jet file stored on the SD card:
여기 SD카드에 저장된 .jet 파일로부터 제트JET 재생을 설정하는 방법에 대한 예제가 있다.
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.
SDK는 이것에 대한 예제 애플리케이션, JetBoy를 포함하고 있다. 그것은 여러분의 게임에 인터랙티브 뮤직 사운드트랙을 생성하기 위해 제트플레이어JetPlayer를 사용하는 방법을 보여준다. 그것은 또한 뮤직과 게임 로직을 동기화하기 위해 제트JET 이벤트를 사용하는 방법을 설명한다. 애플리케이션은 <sdk>/platforms/android-1.5/samples/JetBoy에 위치해 있다.
Audio capture from the device is a bit more complicated than audio/video playback, but still fairly simple:
디바이스로부터 오디오를 캡쳐하는 것은 오디오/비디오 재생보다는 좀 더 복잡하지만, 여전히 꽤 간단하다.
android.media.MediaRecorder using newandroid.content.ContentValues and put in some standard properties like
TITLE, TIMESTAMP, and the all important
MIME_TYPEandroid.content.ContentResolver to
create an entry in the Content database and get it to assign a path
automatically which you can then use)MediaRecorder.setAudioSource(). You will probably want to use
MediaRecorder.AudioSource.MICMediaRecorder.setOutputFormat()
MediaRecorder.setAudioEncoder()
prepare()
on the MediaRecorder instance.start(). stop().
release() on it. 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();
Based on the example above, here's how you would stop audio capture.
위의 예제에 기반하여, 여기에 여러분이 오디오 캡쳐를 중지하는 방법이 있다.
recorder.stop();
recorder.release();