gpt4 book ai didi

java - 我如何将声音从原始 View 带到 ListView 并更改它们的名称?

转载 作者:行者123 更新时间:2023-12-02 11:18:35 26 4
gpt4 key购买 nike

我必须从原始数据中获取声音并在listview中显示它们,我可以做到这一点,但名称与原始数据中的文件夹名称相同。

如何用我想要的名称更改它们?(还将播放的歌曲写入 TextView )

Here is my code :

 MediaPlayer mp;
Uri uri;

ListView listView;
TextView textBilgi;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_giris);

Field[] fields = R.raw.class.getFields();
String[] mediaList = new String[fields.length];
for (int count = 0; count < fields.length; count++)
mediaList[count] = fields[count].getName();



textBilgi = (TextView) findViewById(R.id.textBilgi1);
listView = (ListView) findViewById(R.id.listview);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
giris.this, android.R.layout.simple_list_item_1,
mediaList);
listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


String uri = "android.resource://" + getPackageName() + "/raw/"
+ ((TextView) view).getText();



if (mp != null && mp.isPlaying())
mp.stop();

mp = MediaPlayer.create(getApplicationContext(), Uri.parse(uri));
mp.start();

textBilgi.setText(((TextView) view).getText() + " ["
+ mp.getDuration() / 1000 + " sn.]");





}
});

}

最佳答案

your_array_list中添加您最喜欢的文件名,然后添加适配器,然后在您的URI文件中添加medialist,然后检查您的问题是否已解决。

public class MediaPlay extends BaseActivity {

MediaPlayer mp;
Uri uri;

ListView listView;
TextView textBilgi;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_giris);

Field[] fields = R.raw.class.getFields();
final String[] mediaList = new String[fields.length];
for (int count = 0; count < fields.length; count++)
mediaList[count] = fields[count].getName();


textBilgi = (TextView) findViewById(R.id.textBilgi1);
listView = (ListView) findViewById(R.id.listview);

List<String> your_array_list = new ArrayList<String>();
your_array_list.add("Test One");
your_array_list.add("Test Two");
your_array_list.add("Test Three");


ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MediaPlay.this, android.R.layout.simple_list_item_1,
your_array_list);
listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


String uri = "android.resource://" + getPackageName() + "/raw/" + mediaList[position];


if (mp != null && mp.isPlaying())
mp.stop();

mp = MediaPlayer.create(getApplicationContext(), Uri.parse(uri));
mp.start();

textBilgi.setText(((TextView) view).getText() + " ["
+ mp.getDuration() / 1000 + " sn.]");


}
});

}
}

关于java - 我如何将声音从原始 View 带到 ListView 并更改它们的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50086602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com