当前位置: 首页>>代码示例>>Java>>正文


Java MediaExtractor.release方法代码示例

本文整理汇总了Java中android.media.MediaExtractor.release方法的典型用法代码示例。如果您正苦于以下问题:Java MediaExtractor.release方法的具体用法?Java MediaExtractor.release怎么用?Java MediaExtractor.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaExtractor的用法示例。


在下文中一共展示了MediaExtractor.release方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrieveFrameRate

import android.media.MediaExtractor; //导入方法依赖的package包/类
public int retrieveFrameRate() {
    MediaExtractor extractor = new MediaExtractor();
    int frameRate = -1;
    try {
        //Adjust data source as per the requirement if file, URI, etc.
        extractor.setDataSource(getPath());
        int numTracks = extractor.getTrackCount();
        for (int i = 0; i < numTracks; i++) {
            MediaFormat format = extractor.getTrackFormat(i);
            if (format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
                frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        //Release stuff
        extractor.release();
    }
    return frameRate;
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:22,代码来源:Video.java

示例2: getDuration

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * 获取视频信息
 *
 * @param url
 * @return
 */
public static long getDuration(String url) {
	try {
		MediaExtractor mediaExtractor = new MediaExtractor();
		mediaExtractor.setDataSource(url);
		int videoExt = TrackUtils.selectVideoTrack(mediaExtractor);
		if(videoExt == -1){
			videoExt = TrackUtils.selectAudioTrack(mediaExtractor);
			if(videoExt == -1){
				return 0;
			}
		}
		MediaFormat mediaFormat = mediaExtractor.getTrackFormat(videoExt);
		long res = mediaFormat.containsKey(MediaFormat.KEY_DURATION) ? mediaFormat.getLong(MediaFormat.KEY_DURATION) : 0;//时长
		mediaExtractor.release();
		return res;
	} catch (Exception e) {
		return 0;
	}
}
 
开发者ID:yangjie10930,项目名称:EpMedia,代码行数:26,代码来源:VideoUitls.java

示例3: music

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * 添加背景音乐
 *
 * @param videoin          视频文件
 * @param audioin          音频文件
 * @param output           输出路径
 * @param videoVolume      视频原声音音量(例:0.7为70%)
 * @param audioVolume      背景音乐音量(例:1.5为150%)
 * @param onEditorListener 回调监听
 */
public static void music(String videoin, String audioin, String output, float videoVolume, float audioVolume, OnEditorListener onEditorListener) {
	MediaExtractor mediaExtractor = new MediaExtractor();
	try {
		mediaExtractor.setDataSource(videoin);
	} catch (IOException e) {
		e.printStackTrace();
		return;
	}
	int at = TrackUtils.selectAudioTrack(mediaExtractor);
	CmdList cmd = new CmdList();
	cmd.append("ffmpeg").append("-y").append("-i").append(videoin);
	if (at == -1) {
		int vt = TrackUtils.selectVideoTrack(mediaExtractor);
		float duration = (float) mediaExtractor.getTrackFormat(vt).getLong(MediaFormat.KEY_DURATION) / 1000 / 1000;
		cmd.append("-ss").append("0").append("-t").append(duration).append("-i").append(audioin).append("-acodec").append("copy").append("-vcodec").append("copy");
	} else {
		cmd.append("-i").append(audioin).append("-filter_complex")
				.append("[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=" + videoVolume + "[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=" + audioVolume + "[a1];[a0][a1]amix=inputs=2:duration=first[aout]")
				.append("-map").append("[aout]").append("-ac").append("2").append("-c:v")
				.append("copy").append("-map").append("0:v:0");
	}
	cmd.append(output);
	mediaExtractor.release();
	execCmd(cmd, 0, onEditorListener);
}
 
开发者ID:yangjie10930,项目名称:EpMedia,代码行数:36,代码来源:EpEditor.java

示例4: isMatchAudioFormat

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * 该音频是否符合采样率是sampleRate,通道数是channelCount,值为-1表示忽略该条件
 * 
 * @param audioFile
 * @param sampleRate
 * @param channelCount
 * @return
 */
public static boolean isMatchAudioFormat(String audioFile, int sampleRate,int channelCount){
	MediaExtractor mex = new MediaExtractor();
    try {
        mex.setDataSource(audioFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    MediaFormat mf = mex.getTrackFormat(0);
    
    boolean result = true;
    if(sampleRate != -1){
    	result = sampleRate == mf.getInteger(MediaFormat.KEY_SAMPLE_RATE);
    }
    
    if(result && channelCount != -1){
    	result = channelCount == mf.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
    }

    mex.release();
    
    return result;
}
 
开发者ID:YeDaxia,项目名称:MusicPlus,代码行数:32,代码来源:MediaUtils.java

示例5: GetMediaFormatPropertyInteger

import android.media.MediaExtractor; //导入方法依赖的package包/类
@TargetApi( Build.VERSION_CODES.JELLY_BEAN )
public static int GetMediaFormatPropertyInteger( Uri uri, String key, int defaultValue ) {
   int value = defaultValue;

   MediaExtractor extractor = new MediaExtractor();
   try {
      extractor.setDataSource( uri.toString() );
   } catch ( IOException e ) {
      e.printStackTrace();
      return value;
   }
   
   MediaFormat format = GetTrackFormat( extractor, MIME_TYPE_AVC );
   extractor.release();

   if ( format.containsKey( key ) ) {
      value = format.getInteger( key );
   }

   return value;
}
 
开发者ID:hoolrory,项目名称:AndroidVideoSamples,代码行数:22,代码来源:MediaHelper.java

示例6: stop

import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
 * Stops the RTSP server but not the Android Service.
 * To stop the Android Service you need to call {@link android.content.Context#stopService(Intent)};
 */
public void stop() {
    if (mListenerThread != null) {
        try {
            if(VERBOSE) Log.v(TAG,"mListenerThread.kill()");
            mListenerThread.kill();
            for ( MediaStream mediaStream : mMediaStreams.values() ) {
                if ( mediaStream != null ) {
                    if (mediaStream.isStreaming()) mediaStream.stop();
                }
            }
            for ( MediaCodec mediaCodec : mMediaCodecs.values() ) {
                if ( mediaCodec != null ) {
                    mediaCodec.release();
                    mediaCodec.stop();
                }
            }
            for(MediaExtractor mediaExtractor : mediaExtractors.values()){
                if(mediaExtractor != null){
                    mediaExtractor.release();
                }

            }
        } catch (Exception e) {
        } finally {
            mListenerThread = null;
        }
    }
}
 
开发者ID:lijundacom,项目名称:AndroidRTSPLib2,代码行数:33,代码来源:RtspServer.java

示例7: feedClipToEncoder

import android.media.MediaExtractor; //导入方法依赖的package包/类
private void feedClipToEncoder() {

      mLastSampleTime = 0;

      MediaCodec decoder = null;

      MediaExtractor extractor = setupExtractorForClip();

      if(extractor == null ) {
         return;
      }

      int trackIndex = getVideoTrackIndex(extractor);
      extractor.selectTrack( trackIndex );

      MediaFormat clipFormat = extractor.getTrackFormat( trackIndex );


      try {
         decoder = MediaCodec.createDecoderByType(MIME_TYPE_AVC );
         mOutputSurface = new OutputSurface();

         decoder.configure( clipFormat, mOutputSurface.getSurface(), null, 0 );
         decoder.start();

         resampleVideo( extractor, decoder);

      } catch (IOException e) {
         Logger.w(TAG, "resize video", e);
      } finally {

         if ( mOutputSurface != null ) {
            mOutputSurface.release();
         }
         if ( decoder != null ) {
            decoder.stop();
            decoder.release();
         }

         if ( extractor != null ) {
            extractor.release();
            extractor = null;
         }
      }
   }
 
开发者ID:aimbrain,项目名称:aimbrain-android-sdk,代码行数:46,代码来源:VideoResizer.java

示例8: feedClipToEncoder

import android.media.MediaExtractor; //导入方法依赖的package包/类
private void feedClipToEncoder( SamplerClip clip ) {

      mLastSampleTime = 0;

      MediaCodec decoder = null;

      MediaExtractor extractor = setupExtractorForClip(clip);
      
      if(extractor == null ) {
         return;
      }
      
      int trackIndex = getVideoTrackIndex(extractor);
      extractor.selectTrack( trackIndex );

      MediaFormat clipFormat = extractor.getTrackFormat( trackIndex );

      if ( clip.getStartTime() != -1 ) {
         extractor.seekTo( clip.getStartTime() * 1000, MediaExtractor.SEEK_TO_PREVIOUS_SYNC );
         clip.setStartTime( extractor.getSampleTime() / 1000 );
      }
      
      try {
         decoder = MediaCodec.createDecoderByType( MediaHelper.MIME_TYPE_AVC );
         mOutputSurface = new OutputSurface();

         decoder.configure( clipFormat, mOutputSurface.getSurface(), null, 0 );
         decoder.start();

         resampleVideo( extractor, decoder, clip );

      } finally {

         if ( mOutputSurface != null ) {
            mOutputSurface.release();
         }
         if ( decoder != null ) {
            decoder.stop();
            decoder.release();
         }

         if ( extractor != null ) {
            extractor.release();
            extractor = null;
         }
      }
   }
 
开发者ID:hoolrory,项目名称:AndroidVideoSamples,代码行数:48,代码来源:VideoResampler.java


注:本文中的android.media.MediaExtractor.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。