我对 MediaMetadataRetriever setdatasource 方法有疑问。我创建了一个简单的项目。main.xml 只有一个 textview,它应该显示 music.mp3 的参数。mp3 在项目原始文件中。mainActivity 看起来像:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tvMain = (TextView)findViewById(R.id.textView_songParam);
// load data file
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
metaRetriever.setDataSource(R.raw.music);
String out = "";
// get mp3 info
out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
out += "\n";
out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
out += "\n";
//out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
//out += "\n";
//out += metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
//out += "\n";
// convert duration to minute:seconds
String duration = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
long dur = Integer.parseInt(duration);
String seconds = String.valueOf(dur % 60);
String minutes = String.valueOf(dur / 60000);
out += "Length: [ " + minutes + "m" + seconds + "s ]\n";
// close object
metaRetriever.release();
// display output
tvMain.setText(out);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
我在这里做错了什么,我在哪里设置数据源?我不明白?