當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaFormat.getString方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ficklerobot,項目名稱:grid-video-viewer,代碼行數:19,代碼來源:DecodeThread.java

示例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;
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:27,代碼來源:StrengthenMp4MuxStore.java

示例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;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:19,代碼來源:MediaController.java

示例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;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:25,代碼來源:MediaExtractorUtils.java

示例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;
}
 
開發者ID:Tai-Kimura,項目名稱:VideoApplication,代碼行數:18,代碼來源:MediaDecoder.java

示例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;
}
 
開發者ID:AndyZhu1991,項目名稱:grafika,代碼行數:22,代碼來源:MoviePlayer.java

示例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;
}
 
開發者ID:Piasy,項目名稱:VideoCRE,代碼行數:17,代碼來源:Mp4Recorder.java

示例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;
}
 
開發者ID:aiyaapp,項目名稱:AAVT,代碼行數:40,代碼來源:Mp4Provider.java

示例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;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:13,代碼來源:MediaCodecListCompat.java

示例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);
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:14,代碼來源:MediaFormatValidator.java

示例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();
    }
 
開發者ID:Tai-Kimura,項目名稱:VideoApplication,代碼行數:41,代碼來源:AudioDecoder.java

示例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;
}
 
開發者ID:Piasy,項目名稱:InsideCodec,代碼行數:15,代碼來源:FrameProducer.java

示例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;
    }
}
 
開發者ID:uestccokey,項目名稱:EZFilter,代碼行數:35,代碼來源:MediaUtil.java

示例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;
}
 
開發者ID:yangjie10930,項目名稱:EpMedia,代碼行數:18,代碼來源:TrackUtils.java

示例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;
    }
}
 
開發者ID:lisnstatic,項目名稱:live_master,代碼行數:16,代碼來源:SrsMp4Muxer.java


注:本文中的android.media.MediaFormat.getString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。