本文整理匯總了Java中android.media.MediaFormat.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaFormat.getString方法的具體用法?Java MediaFormat.getString怎麽用?Java MediaFormat.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.MediaFormat
的用法示例。
在下文中一共展示了MediaFormat.getString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: selectTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
private MediaFormat selectTrack(MediaExtractor extractor) {
int trackCount = extractor.getTrackCount();
Log.d(TAG, "trackCount :" + trackCount);
MediaFormat format;
for (int i = 0; i < trackCount; i++) {
extractor.selectTrack(i);
format = extractor.getTrackFormat(i);
Log.d(TAG, "Track media format :" + format.toString());
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
return format;
}
}
return null;
}
示例2: addTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
public int addTrack(MediaFormat mediaFormat) {
int ret=-1;
synchronized (Lock){
if(!muxStarted){
if(audioTrack==-1&&videoTrack==-1){
try {
mMuxer=new MediaMuxer(path,MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
} catch (IOException e) {
e.printStackTrace();
AvLog.e("create MediaMuxer failed:"+e.getMessage());
}
}
String mime=mediaFormat.getString(MediaFormat.KEY_MIME);
if(mime.startsWith("audio")){
audioTrack=mMuxer.addTrack(mediaFormat);
ret=audioTrack;
}else if(mime.startsWith("video")){
videoTrack=mMuxer.addTrack(mediaFormat);
ret=videoTrack;
}
startMux();
}
}
return ret;
}
示例3: selectTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
@TargetApi(16)
private int selectTrack(MediaExtractor extractor, boolean audio) {
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (audio) {
if (mime.startsWith("audio/")) {
return i;
}
} else {
if (mime.startsWith("video/")) {
return i;
}
}
}
return -5;
}
示例4: getFirstVideoAndAudioTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
public static TrackResult getFirstVideoAndAudioTrack(MediaExtractor extractor) {
TrackResult trackResult = new TrackResult();
trackResult.mVideoTrackIndex = -1;
trackResult.mAudioTrackIndex = -1;
int trackCount = extractor.getTrackCount();
for (int i = 0; i < trackCount; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (trackResult.mVideoTrackIndex < 0 && mime.startsWith("video/")) {
trackResult.mVideoTrackIndex = i;
trackResult.mVideoTrackMime = mime;
trackResult.mVideoTrackFormat = format;
} else if (trackResult.mAudioTrackIndex < 0 && mime.startsWith("audio/")) {
trackResult.mAudioTrackIndex = i;
trackResult.mAudioTrackMime = mime;
trackResult.mAudioTrackFormat = format;
}
if (trackResult.mVideoTrackIndex >= 0 && trackResult.mAudioTrackIndex >= 0) break;
}
if (trackResult.mVideoTrackIndex < 0 || trackResult.mAudioTrackIndex < 0) {
throw new IllegalArgumentException("extractor does not contain video and/or audio tracks.");
}
return trackResult;
}
示例5: selectTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
protected int selectTrack() {
if (mWeakPlayer == null || mWeakPlayer.get() == null)
return -1;
// Select the first video track we find, ignore the rest.
int numTracks = mExtractor.getTrackCount();
for (int i = 0; i < numTracks; i++) {
MediaFormat format = mExtractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
Log.d(TAG, "track: " + mime);
if (mime.startsWith(TRACK_TYPE + "/")) {
Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
return i;
}
}
return -1;
}
示例6: selectTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
/**
* Selects the video track, if any.
*
* @return the track index, or -1 if no video track is found.
*/
private static int selectTrack(MediaExtractor extractor) {
// Select the first video track we find, ignore the rest.
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
if (VERBOSE) {
Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
}
return i;
}
}
return -1;
}
示例7: onOutputFormatChanged
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
public void onOutputFormatChanged(final MediaCodec codec, final MediaFormat format) {
if (mMuxerStarted) {
throw new RuntimeException("format changed twice");
}
String name = format.getString(MediaFormat.KEY_MIME);
int width = format.getInteger(MediaFormat.KEY_WIDTH);
int height = format.getInteger(MediaFormat.KEY_HEIGHT);
Logging.d(TAG, "onOutputFormatChanged " + name + " " + width + "x" + height);
mTrackIndex = mMediaMuxer.addTrack(format);
mMediaMuxer.start();
mMuxerStarted = true;
}
示例8: extractMedia
import android.media.MediaFormat; //導入方法依賴的package包/類
private boolean extractMedia(){
if(mPath==null||!new File(mPath).exists()){
//文件不存在
return false;
}
try {
MediaMetadataRetriever mMetRet=new MediaMetadataRetriever();
mMetRet.setDataSource(mPath);
mVideoTotalTime=Long.valueOf(mMetRet.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
mExtractor=new MediaExtractor();
mExtractor.setDataSource(mPath);
int trackCount=mExtractor.getTrackCount();
for (int i=0;i<trackCount;i++){
MediaFormat format=mExtractor.getTrackFormat(i);
String mime=format.getString(MediaFormat.KEY_MIME);
if(mime.startsWith("audio")){
mAudioDecodeTrack=i;
}else if(mime.startsWith("video")){
mVideoDecodeTrack=i;
int videoRotation=0;
String rotation=mMetRet.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
if(rotation!=null){
videoRotation=Integer.valueOf(rotation);
}
if(videoRotation%180!=0){
mVideoSize.y=format.getInteger(MediaFormat.KEY_WIDTH);
mVideoSize.x=format.getInteger(MediaFormat.KEY_HEIGHT);
}else{
mVideoSize.x=format.getInteger(MediaFormat.KEY_WIDTH);
mVideoSize.y=format.getInteger(MediaFormat.KEY_HEIGHT);
}
}
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
示例9: findCoderForFormat
import android.media.MediaFormat; //導入方法依賴的package包/類
private String findCoderForFormat(MediaFormat format, boolean findEncoder) {
String mimeType = format.getString(MediaFormat.KEY_MIME);
Iterator<MediaCodecInfo> iterator = new MediaCodecInfoIterator();
while (iterator.hasNext()) {
MediaCodecInfo codecInfo = iterator.next();
if (codecInfo.isEncoder() != findEncoder) continue;
if (Arrays.asList(codecInfo.getSupportedTypes()).contains(mimeType)) {
return codecInfo.getName();
}
}
return null;
}
示例10: validateVideoOutputFormat
import android.media.MediaFormat; //導入方法依賴的package包/類
public static void validateVideoOutputFormat(MediaFormat format) {
String mime = format.getString(MediaFormat.KEY_MIME);
// Refer: http://developer.android.com/guide/appendix/media-formats.html#core
// Refer: http://en.wikipedia.org/wiki/MPEG-4_Part_14#Data_streams
if (!MediaFormatExtraConstants.MIMETYPE_VIDEO_AVC.equals(mime)) {
throw new InvalidOutputFormatException("Video codecs other than AVC is not supported, actual mime type: " + mime);
}
ByteBuffer spsBuffer = AvcCsdUtils.getSpsBuffer(format);
byte profileIdc = AvcSpsUtils.getProfileIdc(spsBuffer);
if (profileIdc != PROFILE_IDC_BASELINE) {
throw new InvalidOutputFormatException("Non-baseline AVC video profile is not supported by Android OS, actual profile_idc: " + profileIdc);
}
}
示例11: prepare
import android.media.MediaFormat; //導入方法依賴的package包/類
@Override
protected void prepare() throws IOException {
if (mState < STATE_PREPARED) {
MediaFormat format;
if (mState == STATE_UNINITIALIZED) {
mTrackIndex = selectTrack();
if (mTrackIndex < 0) {
setState(STATE_NO_TRACK_FOUND);
return;
}
mExtractor.selectTrack(mTrackIndex);
format = mExtractor.getTrackFormat(mTrackIndex);
mSampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int audioChannels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
mAudioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
mSampleRate,
(audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
AudioFormat.ENCODING_PCM_16BIT,
AudioTrack.getMinBufferSize(
mSampleRate,
(audioChannels == 1 ? AudioFormat.CHANNEL_OUT_MONO : AudioFormat.CHANNEL_OUT_STEREO),
AudioFormat.ENCODING_PCM_16BIT
),
AudioTrack.MODE_STREAM
);
mState = STATE_INITIALIZED;
} else {
format = mExtractor.getTrackFormat(mTrackIndex);
}
String mime = format.getString(MediaFormat.KEY_MIME);
Log.d(TAG, mime);
mMediaCodec = MediaCodec.createDecoderByType(mime);
// mMediaCodec.setCallback(mCallback);
mMediaCodec.configure(format, null, null, 0);
setState(STATE_PREPARED);
}
super.prepare();
}
示例12: selectVideoTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
private int selectVideoTrack(MediaExtractor extractor) {
// Select the first video track we find, ignore the rest.
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
Log.i(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
return i;
}
}
return -1;
}
示例13: getFirstTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
/**
* 讀取多媒體第一個視頻軌和音頻軌
*
* @param extractor
* @return
*/
public static Track getFirstTrack(MediaExtractor extractor) {
Track track = new Track();
track.videoTrackIndex = -1;
track.audioTrackIndex = -1;
int trackCount = extractor.getTrackCount();
for (int i = 0; i < trackCount; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (track.videoTrackIndex < 0 && mime.startsWith("video/")) {
track.videoTrackIndex = i;
track.videoTrackMime = mime;
track.videoTrackFormat = format;
} else if (track.audioTrackIndex < 0 && mime.startsWith("audio/")) {
track.audioTrackIndex = i;
track.audioTrackMime = mime;
track.audioTrackFormat = format;
}
if (track.videoTrackIndex >= 0 && track.audioTrackIndex >= 0) break;
}
if (track.videoTrackIndex < 0 && track.audioTrackIndex < 0) {
// 視頻軌和音軌都沒有
Log.e("ExtractorUtil", "Not found video/audio track.");
return null;
} else {
return track;
}
}
示例14: selectVideoTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
/**
* 查找視頻軌道
* @param extractor
* @return
*/
public static int selectVideoTrack(MediaExtractor extractor) {
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
Log.d(TAG, "Extractor selected track " + i + " (" + mime + "): " + format);
return i;
}
}
return -1;
}
示例15: addTrack
import android.media.MediaFormat; //導入方法依賴的package包/類
/**
* Adds a track with the specified format.
*
* @param format The media format for the track.
* @return The track index for this newly added track.
*/
public int addTrack(MediaFormat format) {
if (format.getString(MediaFormat.KEY_MIME) == MediaFormat.MIMETYPE_VIDEO_AVC) {
videoFormat = format;
return VIDEO_TRACK;
} else {
audioFormat = format;
return AUDIO_TRACK;
}
}