本文整理汇总了Java中android.media.MediaExtractor.setDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java MediaExtractor.setDataSource方法的具体用法?Java MediaExtractor.setDataSource怎么用?Java MediaExtractor.setDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaExtractor
的用法示例。
在下文中一共展示了MediaExtractor.setDataSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readyExtractor
import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
* 現在のfilePathを使ってExtractorを作成する
*/
private boolean readyExtractor(String filePath) {
boolean isOk = false;
mBufferinfo = new MediaCodec.BufferInfo();
try {
mExtractor = new MediaExtractor();
mExtractor.setDataSource(filePath);
isOk = true;
} catch (IOException e) {
e.printStackTrace();
Log.d(TAG, "Failed to setDataSource id:" + id);
mVideoData = null;
}
return isOk;
}
示例2: initExtractor
import android.media.MediaExtractor; //导入方法依赖的package包/类
public boolean initExtractor(String filePath) throws IOException {
decoding = false;
audioExtractor = new MediaExtractor();
audioExtractor.setDataSource(filePath);
for (int i = 0; i < audioExtractor.getTrackCount() && !mime.startsWith("audio/"); i++) {
audioFormat = audioExtractor.getTrackFormat(i);
mime = audioFormat.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("audio/")) {
audioExtractor.selectTrack(i);
} else {
audioFormat = null;
}
}
if (audioFormat != null && mime.equals("audio/mp4a-latm")) {
isStereo = (audioFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT) == 2);
sampleRate = audioFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
return true;
//audio decoder not supported
} else {
mime = "";
audioFormat = null;
return false;
}
}
示例3: initExtractor
import android.media.MediaExtractor; //导入方法依赖的package包/类
public boolean initExtractor(String filePath) throws IOException {
decoding = false;
videoExtractor = new MediaExtractor();
videoExtractor.setDataSource(filePath);
for (int i = 0; i < videoExtractor.getTrackCount() && !mime.startsWith("video/"); i++) {
videoFormat = videoExtractor.getTrackFormat(i);
mime = videoFormat.getString(MediaFormat.KEY_MIME);
if (mime.startsWith("video/")) {
videoExtractor.selectTrack(i);
} else {
videoFormat = null;
}
}
if (videoFormat != null && mime.equals("video/avc")) {
width = videoFormat.getInteger(MediaFormat.KEY_WIDTH);
height = videoFormat.getInteger(MediaFormat.KEY_HEIGHT);
return true;
//video decoder not supported
} else {
mime = "";
videoFormat = null;
return false;
}
}
示例4: 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;
}
示例5: 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;
}
}
示例6: 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);
}
示例7: concatVideoListFromMediaCodec
import android.media.MediaExtractor; //导入方法依赖的package包/类
private static void concatVideoListFromMediaCodec(List<String> pathList,
String destinationVideoFilePath, int videoRotation,
ConcatMediaCallback concatMediaCallback) throws IOException {
MediaExtractor extractor = new MediaExtractor();
MediaFormat format = null;
extractor.setDataSource(pathList.get(0));
int numTracks = extractor.getTrackCount();
// find and select the first audio track present in the file.
for (int i = 0; i < numTracks; i++) {
format = extractor.getTrackFormat(i);
if (format.getString(MediaFormat.KEY_MIME).startsWith("audio/")) {
extractor.selectTrack(i);
break;
}
}
MediaCodec mediaCodec = MediaCodec.createDecoderByType(format.getString(MediaFormat.KEY_MIME));
mediaCodec.configure(format, null, null, 0);
mediaCodec.start();
}
示例8: initMediaExtractor
import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
* Initialize a MediaExctractor if needed
* @throws IOException
*/
private void initMediaExtractor() throws IOException{
String filePath = Environment.getExternalStorageDirectory().getPath() + "/rpi960mal810.h264";
//String filePath = "/storage/sdcard/rpi960mal810.h264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/somefile2.264"; //???
//String filePath = "/storage/external_SD/movies/scut1.avi"; //???
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat.h264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/ravi2.264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/testfile.264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat90.h264";
File f = new File(filePath);
boolean ext = f.exists();
mediaExtractor = new MediaExtractor();
mediaExtractor.setDataSource(filePath);
int trackCount = mediaExtractor.getTrackCount();
if(trackCount != 1){
// throw new RuntimeException("TrackCount = " + trackCount + ". Only Single Track is supported");
}
mediaExtractor.selectTrack(0);
}
示例9: initMediaExtractor
import android.media.MediaExtractor; //导入方法依赖的package包/类
/**
* Initialize a MediaExctractor if needed
* @throws IOException
*/
private void initMediaExtractor() throws IOException{
String filePath = Environment.getExternalStorageDirectory().getPath() + "/rpi960mal810.h264";
//String filePath = "/storage/sdcard/rpi960mal810.h264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/somefile2.264"; //???
//String filePath = "/storage/external_SD/movies/scut1.avi"; //???
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat.h264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/ravi2.264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/testfile.264";
//String filePath = Environment.getExternalStorageDirectory().getPath() + "/vv/cat90.h264";
File f = new File(filePath);
boolean ext = f.exists();
mediaExtractor = new MediaExtractor();
mediaExtractor.setDataSource(filePath);
int trackCount = mediaExtractor.getTrackCount();
if(trackCount != 1){
// throw new RuntimeException("TrackCount = " + trackCount + ". Only Single Track is supported");
}
mediaExtractor.selectTrack(0);
}
示例10: initStream
import android.media.MediaExtractor; //导入方法依赖的package包/类
public void initStream() throws Exception {
mLock.lock();
try {
mExtractor = new MediaExtractor();
if (!TextUtils.isEmpty(mPath)) {
mExtractor.setDataSource(mPath);
} else if (mUri != null) {
mExtractor.setDataSource(mContext, mUri, null);
} else {
throw new IOException();
}
} catch (Exception e) {//IOException
throw e;
} finally {
mLock.unlock();
}
initConfig();
}
示例11: 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;
}
示例12: MP4Encorder
import android.media.MediaExtractor; //导入方法依赖的package包/类
public MP4Encorder(Session session){
mediaExtractor = new MediaExtractor();
try {
mediaExtractor.setDataSource(session.getVideoPath());
} catch (IOException e) {
e.printStackTrace();
}
for(int i = 0; i < mediaExtractor.getTrackCount(); i++) {
MediaFormat format = mediaExtractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
if (!mime.startsWith("video/")) {
continue;
}
framerate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
mediaExtractor.selectTrack(i);
session.getVideoQuality().setmFrameRate(framerate);
}
}
示例13: prepare
import android.media.MediaExtractor; //导入方法依赖的package包/类
public void prepare(String path) {
mExtractor = new MediaExtractor();
try {
mExtractor.setDataSource(path);
} catch (IOException e) {
e.printStackTrace();
}
int tracks = mExtractor.getTrackCount();
for (int i = 0; i < tracks; i++) {
MediaFormat format = mExtractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
Logs.i(TAG, "mime = " + mime);
}
mExtractor.selectTrack(0);
mAudioBuffer = ByteBuffer.allocate(1024);
next();;
}
示例14: prepareAudio
import android.media.MediaExtractor; //导入方法依赖的package包/类
private MediaExtractor prepareAudio(String path) {
MediaExtractor mExtractor = new MediaExtractor();
try {
mExtractor.setDataSource(path);
} catch (IOException e) {
e.printStackTrace();
}
int tracks = mExtractor.getTrackCount();
for (int i = 0; i < tracks; i++) {
MediaFormat format = mExtractor.getTrackFormat(i);
String mime = format.getString(MediaFormat.KEY_MIME);
Logs.i(TAG, "mime = " + mime);
}
mExtractor.selectTrack(0);
return mExtractor;
}
示例15: prepare
import android.media.MediaExtractor; //导入方法依赖的package包/类
@Override
public boolean prepare() throws IOException {
if (!prepared) {
extractor = new MediaExtractor();
extractor.setDataSource(context, uri, headers);
trackStates = new int[extractor.getTrackCount()];
pendingDiscontinuities = new boolean[trackStates.length];
trackInfos = new TrackInfo[trackStates.length];
for (int i = 0; i < trackStates.length; i++) {
android.media.MediaFormat format = extractor.getTrackFormat(i);
long durationUs = format.containsKey(android.media.MediaFormat.KEY_DURATION) ?
format.getLong(android.media.MediaFormat.KEY_DURATION) : C.UNKNOWN_TIME_US;
String mime = format.getString(android.media.MediaFormat.KEY_MIME);
trackInfos[i] = new TrackInfo(mime, durationUs);
}
prepared = true;
}
return true;
}