001/* 002 * Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com> 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.baidu.cloud.media.player.misc; 018 019import android.annotation.TargetApi; 020import android.media.MediaFormat; 021import android.os.Build; 022 023public class AndroidMediaFormat implements IMediaFormat { 024 private final MediaFormat mMediaFormat; 025 026 public AndroidMediaFormat(MediaFormat mediaFormat) { 027 mMediaFormat = mediaFormat; 028 } 029 030 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 031 @Override 032 public int getInteger(String name) { 033 if (mMediaFormat == null) { 034 return 0; 035 } 036 037 return mMediaFormat.getInteger(name); 038 } 039 040 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 041 @Override 042 public String getString(String name) { 043 if (mMediaFormat == null) { 044 return null; 045 } 046 047 return mMediaFormat.getString(name); 048 } 049 050 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) 051 @Override 052 public String toString() { 053 StringBuilder out = new StringBuilder(128); 054 out.append(getClass().getName()); 055 out.append('{'); 056 if (mMediaFormat != null) { 057 out.append(mMediaFormat.toString()); 058 } else { 059 out.append("null"); 060 } 061 out.append('}'); 062 return out.toString(); 063 } 064}