Androidトレーニングプロジェクト:メモリーカードミュージックプレーヤーV04(トレーニングログ)に基づく

##トレーニングプロジェクトの最初の段階:ストレージカード音楽プレーヤーV04に基づく

1)機能要件
メモリーカードミュージックプレーヤーV0.3に基づいて、以下の変更を行います。

作成メソッドは、メモリカード上のすべてのmp3ファイルをスキャンできます(再帰的アルゴリズムを
使用)。カスタムアプリケーションクラスを使用してグローバルデータとメソッドを保存します。
非同期タスクを使用して、時間のかかるメモリカードスキャンを完了します。
説明:にディレクトリがほとんどありませんエミュレータのメモリカードなので、スキャンは非常に簡単です。ほぼ完了しており、進行状況バーがほとんどありません。テストするには、実際のマシンでプログラムを実行することをお勧めします。
(2)ランニング効果
ここに画像の説明を挿入します
(3)知識ポイントの関与
1.ラベル(TextView)
2。ボタン(ボタン)
3。メディアプレーヤー(MediaPlayer)
4。プログレスバー(ProgressBar)
5。スレッド(スレッド)
6。メッセージプロセッサー(ハンドラー
7 。リストビュー(ListView)
8。非同期タスク(AsyncTask)
9。アプリケーション(アプリケーション)
10。再帰的アルゴリズム
(4)実装手順
1.画像素材をドローアブルディレクトリとmipmapディレクトリにコピーします
ここに画像の説明を挿入します
ここに画像の説明を挿入します

2.ボタン背景画像セレクター
(1)再生ボタン背景画像セレクター-play_button_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/play_button_pressed" android:state_pressed="true" />
    <item android:drawable="@drawable/play_button" android:state_pressed="false" />
</selector>

(2)一時停止ボタンの背景画像セレクター-pause_button_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/pause_button_pressed" android:state_pressed="true" />
    <item android:drawable="@drawable/pause_button" android:state_pressed="false" />
</selector>

(3)前のボタンの背景画像セレクター-previous_button_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/previous_button_pressed" android:state_pressed="true" />
    <item android:drawable="@drawable/previous_button" android:state_pressed="false" />
</selector>

(4)次のボタンの背景画像セレクター-next_button_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/next_button_pressed" android:state_pressed="true" />
    <item android:drawable="@drawable/next_button" android:state_pressed="false" />
</selector>

3.メインレイアウトリソースファイルactivity_main.xml
ここに画像の説明を挿入します

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:orientation="vertical"
    android:padding="20dp"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ProgressBar
            android:id="@+id/pbScanMusic"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/tvScanMusic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/scan_music"
            android:textColor="#0000ff"
            android:textSize="25sp"
            android:visibility="gone" />
    </LinearLayout>

    <ListView
        android:id="@+id/lvMusicName"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginBottom="16dp"
        android:layout_weight="8" />

    <TextView
        android:id="@+id/tvMusicName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:textColor="#0000ff"
        android:textSize="20sp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_weight="0.5"
        android:gravity="center"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tvCurrentPosition"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#ff0000" />

        <ProgressBar
            android:id="@+id/pbMusicProgress"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6" />

        <TextView
            android:id="@+id/tvDuration"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#ff00ff" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btnPrevious"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:background="@drawable/previous_button_selector"
            android:onClick="doPrevious" />

        <Button
            android:id="@+id/btnPlayOrPause"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:background="@drawable/play_button_selector"
            android:onClick="doPlayOrPause" />

        <Button
            android:id="@+id/btnNext"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:background="@drawable/next_button_selector"
            android:onClick="doNext" />
    </LinearLayout>
</LinearLayout>

4.文字列リソースファイルstrings.xml5
ここに画像の説明を挿入します
。音楽名リストアイテムテンプレートを
ここに画像の説明を挿入します
作成しますmusic_name_list_item.xml6。uiサブパッケージを作成し、MainActivityをuiサブパッケージにドラッグします
ここに画像の説明を挿入します

6.エンティティサブパッケージを作成し、その中に音楽エンティティクラスMusicを
ここに画像の説明を挿入します
作成します。7 アプリサブパッケージを作成し、その中に音楽プレーヤーアプリケーションクラスMusicPlayerApplicationを
ここに画像の説明を挿入します
作成します。8。アダプターサブパッケージを作成し、音楽アダプターを作成しますその中のMusicAdapter。9
ここに画像の説明を挿入します
。メインインターフェイスクラス-MainActivity
(1)変数を宣言し
ここに画像の説明を挿入します
、アプリケーションを起動して、効果を確認します。
ここに画像の説明を挿入します

おすすめ

転載: blog.csdn.net/triet/article/details/112367814