在我的音乐播放器为Android需要帮助 [英] Need assistance on my Music Player for android
问题描述
所以我previously问过类似的问题,只拿到了几点意见话说,谷歌搜索了,我做到了。我什么也没有发现。那么什么是为我工作。
So I previously asked a similar question and only got a few comments saying search up on google, and I did. I found nothing. Well nothing that worked for me.
我想要做的是,扩大我的音乐播放器。例如...我想创建从我的设备会显示所有的音乐文件,内置一个库。当我选择歌曲,它会播放。并在底部,它会显示以下按钮 - 洗牌,previous歌曲,播放/暂停,下一首歌曲,复读功能
What I want to do is, expand my music player. for example... I would like to create an inbuilt library that displays all the music files from my device. And when I select the song it'll play. And at the bottom it'll display the following buttons - shuffle, previous song, play/pause, next song, repeat function"
下面是我的MainActivity -
Here's my MainActivity -
package com.ascendapps.holoplayer;
import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button play = (Button) findViewById(R.id.play);
play.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Uri path = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.dummy);
mediaPlayer = MediaPlayer.create(MainActivity.this, path);
mediaPlayer.start();
}
});
Button stop = (Button) findViewById(R.id.stop);
stop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
}
}
});
}
// --
@Override
protected void onDestroy() {
if(mediaPlayer!=null && mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();mediaPlayer = null;
}
super.onDestroy();
}
}
这是我的activity_main.xml中
And here is my activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
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=".MainActivity" >
<Button
android:id="@+id/play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2.5dip"
android:background="#ff4c4c"
android:text="@string/Play" />
<Button
android:id="@+id/stop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2.5dip"
android:background="#4cb4ff"
android:text="@string/Stop" />
</LinearLayout>
这是如何做到以上将是好心AP preciated任何帮助。
Any help on how to do the above will be kindly appreciated.
推荐答案
按照以下的 http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/ 我希望你会得到你想要的一切。
Follow this http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/ I hope you will get everything you want.
这篇关于在我的音乐播放器为Android需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!