当前位置: 首页>>代码示例>>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;未经允许,请勿转载。