最近在做播放器項(xiàng)目,由于Android兼容性問題,硬解各種不兼容搞得項(xiàng)目組成員焦頭爛額,為了方便測(cè)試分析,我做了個(gè)小工具,來測(cè)試不同的Android手機(jī)支持的×××格式以及×××名稱。為防止,以后遺忘,在這里寫篇博客記錄之。
成都創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),彌勒網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:彌勒等地區(qū)。彌勒做網(wǎng)站價(jià)格咨詢:18982081108MainActivity代碼:
@SuppressLint("NewApi")
public class MainActivity extends Activity implements OnClickListener {
private ListView decoder
List;
private 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("正在檢測(cè)...");
int numCodecs = MediaCodecList.getCodecCount();
HashMap
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("開始檢測(cè)");
return null;
}
}
斜體加粗部分是核心函數(shù)。
ListView適配器:
public class DecodeListAdapter extends BaseAdapter {
private ArrayList
private Context context;
public DecodeListAdapter(Context context,
ArrayList
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
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" >
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="開始檢測(cè)" /> android:id="@+id/decoderType" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1.0" android:gravity="center" />
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。