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


Java MediaMetadataRetriever.setDataSource方法代码示例

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


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

示例1: getAlbumArtFromMP3File

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.GINGERBREAD_MR1)
public static Bitmap getAlbumArtFromMP3File(String path) {
    MediaMetadataRetriever mmr = new MediaMetadataRetriever();
    try {
        mmr.setDataSource(path);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return null;
    }
    byte[] bytes = mmr.getEmbeddedPicture();
    if (null != bytes) {
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    } else {
        return mmr.getFrameAtTime();
    }
}
 
开发者ID:piyell,项目名称:NeteaseCloudMusic,代码行数:17,代码来源:MP3Util.java

示例2: getFileMeta

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
 * Used to get information about the written file
 */
private void getFileMeta() {

    if (absolutePath != null) {

        try {

            final MediaMetadataRetriever mmr = new MediaMetadataRetriever();
            mmr.setDataSource(absolutePath);
            final String duration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
            mmr.release();

            if (DEBUG) {
                MyLog.i(CLS_NAME, "recording duration: " + duration);
            }

        } catch (final RuntimeException e) {
            if (DEBUG) {
                MyLog.w(CLS_NAME, "RuntimeException: completeFileWrite");
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:27,代码来源:FileCreator.java

示例3: getVideoInfor

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/** 获取视频时长 **/
public static void getVideoInfor(int index) {
	MediaMetadataRetriever mmr = new MediaMetadataRetriever();
	VideoInfo vInfo = videosInfo.get(index);
	mmr.setDataSource(vInfo.videoPath);
	String videoTime = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); // 播放时长单位为毫秒
	String width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
	String height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
	String rotation = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);

	if (rotation.equals("90") || rotation.equals("270")) {
		width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
		height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
	}
	vInfo.rotation = Integer.parseInt(rotation);
	vInfo.videoTime = Integer.parseInt(videoTime);
	vInfo.totalVideoTime = Integer.parseInt(videoTime);
	vInfo.endVideoTime = Integer.parseInt(videoTime);
	
	
	vInfo.width = Integer.parseInt(width);
	vInfo.height = Integer.parseInt(height);
}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:24,代码来源:StaticMethod.java

示例4: generateVideoThumbnail

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private ThumbnailData generateVideoThumbnail(MasterSecret masterSecret, AttachmentId attachmentId) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
    Log.w(TAG, "Video thumbnails not supported...");
    return null;
  }

  File mediaFile = getAttachmentDataFile(attachmentId, DATA);

  if (mediaFile == null) {
    Log.w(TAG, "No data file found for video thumbnail...");
    return null;
  }

  EncryptedMediaDataSource dataSource = new EncryptedMediaDataSource(masterSecret, mediaFile);
  MediaMetadataRetriever   retriever  = new MediaMetadataRetriever();
  retriever.setDataSource(dataSource);

  Bitmap bitmap = retriever.getFrameAtTime(1000);

  Log.w(TAG, "Generated video thumbnail...");
  return new ThumbnailData(bitmap);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:23,代码来源:AttachmentDatabase.java

示例5: createAlbumArt

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
 * @Description 获取专辑封面
 * @return 专辑封面bitmap
 */
public static Bitmap createAlbumArt(String path) {
    if (TextUtils.isEmpty(path)) {
        return null;
    }
    Bitmap bitmap = null;
    //能够获取多媒体文件元数据的类
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(path); //设置数据源
        byte[] embedPic = retriever.getEmbeddedPicture(); //得到字节型数据
        if (embedPic != null) {
            bitmap = BitmapFactory.decodeByteArray(embedPic, 0, embedPic.length); //转换为图片
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            retriever.release();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }
    Log.d("zbj1101", "createAlbumArt:bitmap: " + bitmap + ",music: "+path);
    return bitmap;
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:30,代码来源:LocalMusicLibrary.java

示例6: setVideoFromAssets

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public void setVideoFromAssets(String assetsFileName) {
    reset();

    try {
        AssetFileDescriptor assetFileDescriptor = getContext().getAssets().openFd(assetsFileName);
        mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());

        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        retriever.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());

        onDataSourceSet(retriever);

    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    }
}
 
开发者ID:pavelsemak,项目名称:alpha-movie,代码行数:17,代码来源:AlphaMovieView.java

示例7: extractInfoMediaMetadataRetriever

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private String[] extractInfoMediaMetadataRetriever(Uri uri){
  MediaMetadataRetriever retriever = new MediaMetadataRetriever();
  retriever.setDataSource(this, uri);
  String length = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);

  String width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
  String height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
  String res;
  int rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
  if(rotation==90 || rotation==180){
    res = height + "x" + width;
  }else{
    res = width + "x" + height;
  }

  return new String[] {length, res};
}
 
开发者ID:bnsantos,项目名称:android-video-compression,代码行数:18,代码来源:MainActivity.java

示例8: checkIsHaveMetaData

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private boolean checkIsHaveMetaData(Uri fileUri) {
    try {
        MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
        metadataRetriever.setDataSource(this, fileUri);

        contentData = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
        contentLocation = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_LOCATION);
        metadataRetriever.release();

        parsMetaLocation();

        SimpleDateFormat metaDateFormat = new SimpleDateFormat(Constants.VIDEO_META_DATE_MASK);
        violationDate = metaDateFormat.parse(contentData);
        return true;

    } catch (Exception e) {
        e.printStackTrace();
        contentNotReady();
        return false;
    }
}
 
开发者ID:stfalcon-studio,项目名称:patrol-android,代码行数:22,代码来源:UploadVideoActivity.java

示例9: onCreateView

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.layout_player_fragment, container, false);

    mAlbumArt = (ImageView) v.findViewById(R.id.albumArt);
    mSongInfo = (TextView) v.findViewById(R.id.songInfo);

    Bundle bundle = getArguments();
    MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
    metadataRetriever.setDataSource(bundle.getString("filepath"));
    String filepath = bundle.getString("filepath");
    mSongInfo.setText(filepath);


    return v;
}
 
开发者ID:GaneshPg,项目名称:Musico,代码行数:17,代码来源:PlayerFragment.java

示例10: DisplayVideo

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
private void DisplayVideo(final Uri uri) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    retriever.setDataSource(uri.getPath());
    height = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
    width = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
    rotation = Integer.valueOf(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
    Log.d(Config.LOGTAG, "Video height: " + height + ", width: " + width + ", rotation: " + rotation);
    if (useAutoRotateScreen()) {
        rotateScreen(width, height, rotation);
    }
    try {
        mVideo.setVisibility(View.VISIBLE);
        mVideo.setVideoURI(uri);
        mFullscreenbutton.setVisibility(View.INVISIBLE);
        mVideo.setShouldAutoplay(true);

    } catch (IOException e) {
        Toast.makeText(this, getString(R.string.error_file_corrupt), Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
 
开发者ID:kriztan,项目名称:Pix-Art-Messenger,代码行数:22,代码来源:ShowFullscreenMessageActivity.java

示例11: extractBitmap

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static Bitmap extractBitmap(String videoPath, int second) {
	if (TextUtils.isEmpty(videoPath)) {
		logd("extractBitmap empty video path");
		return null;
	}

	MediaMetadataRetriever retriever = new MediaMetadataRetriever();
	retriever.setDataSource(videoPath);
	// 取得视频的长度(单位为毫秒)
	String time = retriever
			.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
	// 取得视频的长度(单位为秒)
	int total = Integer.valueOf(time) / 1000;

	if (second < 0 || second > total) {
		loge("unavalible second(" + second + "), total(" + total + ")");
		return null;
	}

	Bitmap bitmap = retriever.getFrameAtTime(second * 1000 * 1000,
			MediaMetadataRetriever.OPTION_CLOSEST_SYNC);

	return bitmap;
}
 
开发者ID:dxjia,项目名称:GifAssistant,代码行数:25,代码来源:ExtractPicturesWorker.java

示例12: handlePrepare

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
 * @param sourceFile
 * @throws IOException
 */
private final void handlePrepare(final String source_file) throws IOException {
	if (DEBUG) Log.v(TAG, "handlePrepare:");
       synchronized (mSync) {
		if (mState != STATE_STOP) {
			throw new RuntimeException("invalid state:" + mState);
		}
	}
       final File src = new File(source_file);
       if (TextUtils.isEmpty(source_file) || !src.canRead()) {
           throw new FileNotFoundException("Unable to read " + source_file);
       }
       mVideoTrackIndex = -1;
	mMetadata = new MediaMetadataRetriever();
	mMetadata.setDataSource(source_file);
	updateMovieInfo();
	// preparation for video playback
	mVideoTrackIndex = internal_prepare_video(source_file);
	if (mVideoTrackIndex < 0) {
		throw new RuntimeException("No video track found in " + source_file);
	}
	synchronized (mSync) {
		mState = STATE_PREPARED;
	}
	mCallback.onPrepared();
}
 
开发者ID:saki4510t,项目名称:AudioVideoPlayerSample,代码行数:30,代码来源:MediaVideoPlayer.java

示例13: loadVideoThumbnail

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
/**
 * Loads the thumbnail of a video.
 *
 * @param path The path to the video file.
 * @return {@code null} if the loading failed.
 */
public static Bitmap loadVideoThumbnail(String path) {
    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(path);
        byte[] data = retriever.getEmbeddedPicture();
        if (data != null) {
            bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
        }
        if (bitmap == null) {
            bitmap = retriever.getFrameAtTime();
        }
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "MediaMetadataRetriever.setDataSource() fail:" + e.getMessage());
    }
    retriever.release();
    return bitmap;
}
 
开发者ID:jameliu,项目名称:Camera2,代码行数:25,代码来源:LocalDataUtil.java

示例14: loadRotationMetdata

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
static void loadRotationMetdata(final LocalData data) {
    final String path = data.getPath();
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        retriever.setDataSource(path);
        String rotation = retriever.extractMetadata(
            MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
        data.getMetadata().putString(ROTATION_KEY, rotation);

        String val = retriever.extractMetadata(
                MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
        int width = Integer.parseInt(val);

        data.getMetadata().putInt(WIDTH_KEY, width);

        val = retriever.extractMetadata(
                MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
        int height = Integer.parseInt(val);

        data.getMetadata().putInt(HEIGHT_KEY, height);
    } catch (RuntimeException ex) {
        // setDataSource() can cause RuntimeException beyond
        // IllegalArgumentException. e.g: data contain *.avi file.
        Log.e(TAG, "MediaMetdataRetriever.setDataSource() fail", ex);
    }
}
 
开发者ID:jameliu,项目名称:Camera2,代码行数:27,代码来源:VideoRotationMetadataLoader.java

示例15: getBitmap

import android.media.MediaMetadataRetriever; //导入方法依赖的package包/类
public static Bitmap getBitmap(Context context, int id, boolean isImage)
{
	String filename = getDataFilepathForMedia(context.getContentResolver(), id, isImage);
	
	/* ttt_installer:remove_line */Log.d(GTG.TAG,"Loading bitmap for "+filename);
	
	if(filename == null)
		return null;

	if(isImage)
		return new BitmapDrawable(context.getResources(), filename).getBitmap();
	
	MediaMetadataRetriever mmr = new MediaMetadataRetriever();
	mmr.setDataSource(filename);
	return mmr.getFrameAtTime();
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:17,代码来源:Util.java


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