资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Android中获取手机支持的硬件解码器类型以及对应的解码器名称-创新互联

最近在做播放器项目,由于Android兼容性问题,硬解各种不兼容搞得项目组成员焦头烂额,为了方便测试分析,我做了个小工具,来测试不同的Android手机支持的×××格式以及×××名称。为防止,以后遗忘,在这里写篇博客记录之。

成都创新互联公司是一家专注于成都网站建设、网站设计与策划设计,弥勒网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:弥勒等地区。弥勒做网站价格咨询:18982081108

MainActivity代码:

@SuppressLint("NewApi")

public class MainActivity extends Activity implements OnClickListener {

private ListView decoder


List;

private ArrayList> datas = new ArrayList>();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button retrieve = (Button) findViewById(R.id.retrieve);

retrieve.setOnClickListener(this);

decoderList = (ListView) findViewById(R.id.decoderList);

}

@Override

public void onClick(View v) {

// MediaCodecInfo mediaCodecInfo = getSupportDecoder(

// MediaFormat.MIMETYPE_VIDEO_VP8, (Button) v);

getSupportDecoder((Button) v);

}

private MediaCodecInfo getSupportDecoder(Button button) {

button.setText("正在检测...");

int numCodecs = MediaCodecList.getCodecCount();

HashMap map;

for (int i = 0; i < numCodecs; i++) {

MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

map = new HashMap();

if (!codecInfo.isEncoder()) {

continue;

}

map.put("decoderName", codecInfo.getName());

String[] types = codecInfo.getSupportedTypes();

for (int j = 0; j < types.length; j++) {

if (map.containsValue(types[j])) {

continue;

} else {

map.put("decoderType", types[j]);

}

}

datas.add(map);

}

decoderList.setAdapter(new DecodeListAdapter(this, datas));

decoderList.setVisibility(View.VISIBLE);

button.setText("开始检测");

return null;

}

}

斜体加粗部分是核心函数。

ListView适配器:

public class DecodeListAdapter extends BaseAdapter {

private ArrayList> decodeList;

private Context context;

public DecodeListAdapter(Context context,

ArrayList> decodeList) {

this.context = context;

this.decodeList = decodeList;

}

@Override

public int getCount() {

// TODO Auto-generated method stub

return decodeList.size();

}

@Override

public HashMap getItem(int position) {

// TODO Auto-generated method stub

return decodeList.get(position);

}

@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return position;

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

HashMap map = getItem(position);

ViewHolder vh = null;

if (convertView == null) {

convertView = LayoutInflater.from(context).inflate(

R.layout.decode_list_item, null);

vh = new ViewHolder();

vh.decoderName = (TextView) convertView

.findViewById(R.id.decoderName);

vh.decoderType = (TextView) convertView

.findViewById(R.id.decoderType);

convertView.setTag(vh);

} else {

vh = (ViewHolder) convertView.getTag();

}

if (position == 0) {

vh.decoderName.setText("×××名称");

vh.decoderType.setText("×××类型");

} else {

vh.decoderName.setText(map.get("decoderName"));

vh.decoderType.setText(map.get("decoderType"));

}

return convertView;

}

private class ViewHolder {

TextView decoderName;

TextView decoderType;

}

}

activity_main.xml代码:

  xmlns:tools="http://schemas.android.com/tools"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical"

  android:paddingBottom="@dimen/activity_vertical_margin"

  android:paddingLeft="@dimen/activity_horizontal_margin"

  android:paddingRight="@dimen/activity_horizontal_margin"

  android:paddingTop="@dimen/activity_vertical_margin"

  tools:context="com.marller.decoderlist.MainActivity" >

  

    android:id="@+id/retrieve"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:text="开始检测" />

  

    android:id="@+id/decoderList"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:cacheColorHint="#00000000"

    android:visibility="gone" />

decode_list_item.xml代码:

  xmlns:tools="http://schemas.android.com/tools"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="horizontal"

  android:paddingBottom="@dimen/activity_vertical_margin"

  android:paddingTop="@dimen/activity_vertical_margin"

  tools:context="com.marller.decoderlist.MainActivity" >

  

    android:id="@+id/decoderName"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:layout_weight="1.0"

    android:gravity="center"

    android:text="开始检测" />

  

    android:id="@+id/decoderType"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:layout_weight="1.0"

    android:gravity="center" />

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文名称:Android中获取手机支持的硬件解码器类型以及对应的解码器名称-创新互联
当前URL:http://cdkjz.cn/article/jgiih.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220