Android 音楽プレーヤー (3) カルーセル マップ

昨年2年生の時に作ったシンプルな音楽プレーヤーのプロジェクトです。 可能な限りKugou Musicを真似て書いたもので、具体的な機能は以下の通りです。

1: 起動アニメーション: クリックしてプログラムを実行すると、Kugou Music の起動アニメーションに似た 2 秒間のビデオが表示され、非常に印象的です!

2:ログイン登録画面:口座番号とパスワードを入力してログイン情報を確認!

3: カルーセル: Kugou Music とまったく同じように、メイン インターフェイスの上に自動サイクル カルーセルがあり、カルーセルの各画像情報をクリックして、対応する特定のサービスに入ります。非常に余分なポイントです!

4: レコードのターンテーブル、曲同期のプログレスバー、音楽の一時停止/再生/継続/切り替え!

5:音楽検索が実現!

6:動画コラムをプレイ!

7; フィードバック、評価、その他、性別、年齢、ニックネーム、コレクションなど、個人情報インターフェイスのレイアウトを実現!

カルーセルのコードは次のとおりです。

パッケージ com.ypc.xiaoxiongmusic;
android.annotation.SuppressLint をインポートします。
android.content.Intent をインポートします。
android.media.Image をインポートします。
android.net.Uri をインポートします。
android.os.Bundle をインポートします。
android.os.Handler をインポートします。
android.text.TextUtils をインポートします。
android.view.LayoutInflater をインポートします。
android.view.Menu をインポートします。
android.view.MotionEvent をインポートします。
android.view.View をインポートします。
android.view.ViewGroup をインポートします。
android.widget.AdapterView をインポートします。
android.widget.BaseAdapter をインポートします。
android.widget.ImageView をインポートします。
android.widget.ListView をインポートします。
android.widget.SearchView をインポートします。
android.widget.TextView をインポートします。
android.app.Fragment をインポートします。

androidx.viewpager.widget.PagerAdapter をインポートします。
androidx.viewpager.widget.ViewPager をインポートします。
import java.util.ArrayList;
java.util.List をインポートします。
java.util.concurrent.Executors をインポートします。
java.util.concurrent.ScheduledExecutorService をインポートします。
import java.util.concurrent.TimeUnit;

静的な android.view.View.VISIBLE をインポートします。

@SuppressLint("有効なフラグメント")
public class musicFragment extends Fragment {
    リストビュー lv;
    SearchView searchView;
    プライベート ViewPager mViewPaper;
    プライベート List<ImageView> 画像;
    プライベート List<View> ドット;
    プライベート int currentItem;
    //最後の点の位置を記録する
    プライベート int oldPosition = 0;
    //画像のIDを格納
    プライベート int selectedPosition=0;
    プライベート ImageView bf;
    プライベート int[] imageIds = 新しい int[]{
            R.drawable.lunchat1、
            R.drawable.lunchatu2、
            R.drawable.lunchatu3、
            R.drawable.lunchatu2、
            R.drawable.lunchatu3
    };
    //画像のタイトルを格納
    プライベート文字列[]タイトル=新しい文字列[]{
            「また会いましょう、それはまだあなたです」、
            「ずっとこの日を待っていた」
            「また天才少女が帰ってきた」、
            「音楽を想像して、あなたと私を照らしてください」、
            「こんにちは、DY.MEMORY」
    };
    プライベート TextView タイトル。
    プライベート ViewPagerAdapter アダプター。
    プライベート ScheduledExecutorService スケジュールされたExecutorService;
    private static List<Integer> sPics=new ArrayList<>();
    // その時の色をテストするために使用
   /* 静的 {
        sPics.add(R.drawable.b1);
        sPics.add(R.drawable.b2);
        sPics.add(R.drawable.b3);
    }*/
    プライベート ImageView m1、m2、m3、m4;
    プライベート ビュー ビュー;
    public static String[] name={"テヨン(태연) - 들리나요(聞こえますか)","テヨン(태연) - 제주도의푸른밤(済州島の青い夜)","テヨン(태연) ) - 그리고하나 (もう一つあります)」、「テヨン (태연) - Rescue Me」、「テヨン (태연) - My Love (Duet Ver.)」、「ファ・チェンユ - 私は本当にこの世界を愛したい (ライブ) )",
            「華振雨-火星の子供たちとの会話」、「華振雨-王と乞食」、「華振雨-闘牛(ライブ)」、「華振雨-花火の粉」、「華振雨-マッドハウス(ライブ)」 "、"Hua Chenyu- Travel Around"、"Hua Chenyu- Searching"、"Hua Chenyu- 退屈な人々"、"Hua Chenyu- Forever"、"Hua Chenyu- Mayfly"、"Hua Chenyu- We (Live)"、 "Hua Chenyu Woo-Heterogeneous",
            「Hua Chenyu-気になる」、「Hua Chenyu-これが最後の日ではないと信じなければならない」、「Hua Chenyu-ジャックドーボーイ」、「Hua Chenyu-Qi Tian」、「Zhang Yixing-は大丈夫です」 」、「チャン・イーシン-おやすみ」、「チャン・イーシン-一人」、「チャン・イーシン-マスク(ライブ)」、「チャン・イーシン-おばあちゃん」、「チャン・イーシン-私は苦手」、「チャン・イーシン-祈る」 、「テヨン (태연) - Gee (大道芸 Ver.)(Live)」、「テヨン(태연) - 만약에(If) (大道芸 Ver.)(Live)」、
            「テヨン (태연) - bad guy (Busking Ver.) (Live)」、「テヨン (태연) - 기억을걷는시간 (Time to Gather Memories) (Busking Ver.) (Live)」、「レスリー・チャン - Strange You are too beautiful」、「Leslie Cheung - left and right hands」、「Leslie Cheung - at least you (00 Live) (live version)」、「Leslie Cheung-me」};
    public static int[] icons={R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx, R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx
            ,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R .drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx
            ,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R .drawable.musicx,R.drawable.musicx};
    @オーバーライド
    public View onCreateView(LayoutInflater インフレータ、ViewGroup コンテナ、Bundle savedInstanceState){

        View view = inflater.inflate(R.layout.fragment_music, container, false);
        //lv.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, name));
        searchView =view.findViewById(R.id.sv);
        lv=view.findViewById(R.id.lv);
        lv.setTextFilterEnabled(真);
        // 検索テキストリスナーを設定
        searchView.setOnQueryTextListener(新しい SearchView.OnQueryTextListener() {
            // このメソッドは、検索ボタンがクリックされたときにトリガーされます
            @オーバーライド
            public boolean onQueryTextSubmit(文字列クエリ) {
                false を返します。
            }
            // 検索内容が変化したときにこのメソッドをトリガーする
            @オーバーライド
            public boolean onQueryTextChange(String newText) {
                if (!TextUtils.isEmpty(newText)){
                    lv.setFilterText(newText);
                }そうしないと{
                    lv.clearTextFilter();
                }
                false を返します。
            }
        });
        bf=view.findViewById(R.id.bf);
        mViewPaper = (ViewPager)view. findViewById(R.id.vp);
        images = new ArrayList<ImageView>();
        for(int i = 0; i < imageIds.length; i++){
            ImageView imageView = new ImageView(getActivity());
            imageView.setBackgroundResource(imageIds[i]);
            images.add(imageView);
        }
        ドット = 新しい ArrayList<View>();
        dot.add(view.findViewById(R.id.dot_0));
        dot.add(view.findViewById(R.id.dot_1));
        dot.add(view.findViewById(R.id.dot_2));
        dot.add(view.findViewById(R.id.dot_3));
        dot.add(view.findViewById(R.id.dot_4));
        title = (TextView) view.findViewById(R.id.title);
        title.setText(タイトル[0]);
        アダプター = 新しい ViewPagerAdapter();
        mViewPaper.setAdapter(アダプター);
        //イラストのontauchクリックメソッドについて
        mViewPaper.setOnTouchListener(新しいView.OnTouchListener() {
            int フレーク = 0 ;
            public boolean onTouch(View v, MotionEvent event) {
                スイッチ (event.getAction()){
                    ケース MotionEvent.ACTION_DOWN:
                        フレーク = 0 ;
                        壊す ;
                    ケース MotionEvent.ACTION_MOVE:
                        フレーク = 1 ;
                        壊す ;
                    ケース MotionEvent.ACTION_UP :
                        もし (フラグ == 0) {
                            int item = mViewPaper.getCurrentItem();
                            もし (項目 == 0) {
                                インテント インテント = 新しいインテント();
                                Intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//ここにリンクを記入
                                インテント.setData(content_url);
                                startActivity(意図);
                            } それ以外の場合 (項目 == 1) {
                                インテント インテント = 新しいインテント();
                                Intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//ここにリンクを記入
                                インテント.setData(content_url);
                                startActivity(意図);
                            } それ以外の場合 (項目 == 2) {
                                インテント インテント = 新しいインテント();
                                Intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//ここにリンクを記入
                                インテント.setData(content_url);
                                startActivity(意図);
                            } その他の場合 (項目 == 3) {
                                インテント インテント = 新しいインテント();
                                Intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//ここにリンクを記入
                                インテント.setData(content_url);
                                startActivity(意図);
                            } それ以外の場合 (項目 == 4) {
                                インテント インテント = 新しいインテント();
                                Intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//ここにリンクを記入
                                インテント.setData(content_url);
                                startActivity(意図);
                            }
                        }
                        壊す ;
                }
                false を返します。
            }
        });
        mViewPaper.setOnPageChangeListener(新しい ViewPager.OnPageChangeListener() {
            @オーバーライド
            public void onPageSelected(int position) {
                title.setText(タイトル[位置]);
                dot.get(position).setBackgroundResource(R.drawable.red);
                //Toast.makeText(getActivity(),"hurhurhghrui",Toast.LENGTH_SHORT).show();
                dot.get(oldPosition).setBackgroundResource(R.drawable.pure);
                oldPosition = 位置;
                currentItem = 位置;
            }
            @オーバーライド
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }
            @オーバーライド
            public void onPageScrollStateChanged(int arg0) {
            }
        });
        m1=view.findViewById(R.id.m1);
        m2=view.findViewById(R.id.m2);
        m3=view.findViewById(R.id.m3);
         m4=view.findViewById(R.id.m4);
        m1.setOnClickListener(new View.OnClickListener() {
            @オーバーライド
            public void onClick(View ビュー) {
                インテント インテント4=新しいインテント(getActivity(),tukuActivity.class);
                startActivity(intent4);
            }
        });
        m2.setOnClickListener(new View.OnClickListener() {
            @オーバーライド
            public void onClick(View ビュー) {
                インテント インテント5=新しいインテント(getActivity(),paihangbangActivity.class);
                startActivity(intent5);
            }
        });
        m3.setOnClickListener(new View.OnClickListener() {
            @オーバーライド
            public void onClick(View ビュー) {
                インテント インテント6=新しいインテント(getActivity(),fenleiActivity.class);
                startActivity(intent6);
            }
        });
        //ListView listView=view.findViewById(R.id.lv);
        MyBaseAdapter アダプタ=新しい MyBaseAdapter();
        lv.setAdapter(アダプター);
        lv.setOnItemClickListener(新しい AdapterView.OnItemClickListener() {
            @オーバーライド
            public void onItemClick(AdapterView<?> 親、ビュー ビュー、int 位置、長い ID) {
                Intent intent=new Intent(getActivity(),Music_Activity.class);// Intent オブジェクトを作成してチェックを開始
                // Intent オブジェクトにデータを格納する
                intent.putExtra("名前",名前[位置]);
                インテント.putExtra("位置",String.valueOf(位置));
                startActivity(意図);
               lv.setSelector(R.drawable.bf1);
            }
        });
        ビューを返します。
    }

    プライベート クラス ViewPagerAdapter は PagerAdapter を拡張します {

        @オーバーライド
        public int getCount() {
            画像を返します。サイズ();
        }

        @オーバーライド
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }
        @オーバーライド
        public void destroyItem(ViewGroup view, int position, Object object) {
            // TODO 自動生成メソッド スタブ
            view.removeView(images.get(position));
        }
        @オーバーライド
        public Object instantiateItem(ViewGroup view, int position) {
            // TODO 自動生成メソッド スタブ
            view.addView(images.get(position));
            画像を返します.get(位置);
        }
    }
   /* @オーバーライド
    public boolean onCreateOptionsMenu(メニュー メニュー) {
        // メニューを膨らませます。これにより、アイテムが存在する場合はアクション バーにアイテムが追加されます。
        getMenuInflater().inflate(R.menu.main, メニュー);
        true を返します。
    }*/

    /**
     * スレッド プールを使用してアニメーション カルーセルを定期的に実行する
     */
    @オーバーライド
    public void onStart() {
        // TODO 自動生成メソッド スタブ
        super.onStart();
        scheduleExecutorService = Executors.newSingleThreadScheduledExecutor();
        スケジュールされたExecutorService.scheduleWithFixedDelay(
                新しい ViewPageTask(),
                2、
                2、
                TimeUnit.SECONDS);
    }
    /**
     * 画像カルーセルタスク
     * @作者劉雅荘
     *
     */
    プライベート クラス ViewPageTask は Runnable を実装します{
        @オーバーライド
        public void run() {
            currentItem = (currentItem + 1) % imageIds.length;
            mHandler.sendEmptyMessage(0);
        }
    }
    /**
     * 子スレッドから渡されたデータを受け取る
     */
    プライベート ハンドラ mHandler = new Handler(){
        public void handleMessage(android.os.Message msg) {
            mViewPaper.setCurrentItem(currentItem);
        };
    };
    @オーバーライド
    public void onStop() {
        // TODO 自動生成メソッド スタブ
        super.onStop();
        if(予定されたExecutorService != null){
            スケジュールされたExecutorService.shutdown();
            スケジュールされたExecutorService = null;
        }
    }
    class MyBaseAdapter は BaseAdapter を拡張します{
        @オーバーライド
        public int getCount(){return name.length;}
        @オーバーライド
        public Object getItem(int i){戻り値[i];}
        @オーバーライド
        public long getItemId(int i){return i;}

        @オーバーライド
        public View getView(int i ,View convertView, ViewGroup parent) {
            View view=View.inflate(musicFragment.this.getActivity(),R.layout.item_layout,null);
            TextView tv_name=view.findViewById(R.id.item_name);
            ImageView iv=view.findViewById(R.id.iv);
            ImageView bf=view.findViewById(R.id.bf);
            tv_name.setText(名前[i]);
            iv.setImageResource(アイコン[i]);
            ビューを返します。
        }
    }

}

対応する 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:orientation="垂直">
    <検索ビュー
        android:id="@+id/sv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        Android:layout_height="213dp"></androidx.viewpager.widget.ViewPager>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dip"
        android:layout_gravity="下"
android:background="@drawable/pure"
        android:gravity="中心"
        android:orientation="垂直" >

        <TextView
            android:id="@+id/タイトル"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            android:text="写真のタイトル"
            android:textColor="#0C0C0C" />

        <LinearLayout
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            android:layout_marginTop="3dip"
            android:orientation="水平" >

            <見る
                android:id="@+id/dot_0"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>

            <見る
                android:id="@+id/dot_1"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>
            <見る
                アンドロイド:id="@+id/dot_2"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>
            <見る
                アンドロイド:id="@+id/dot_3"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>
            <見る
                アンドロイド:id="@+id/dot_4"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>

        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="83dp"
        android:orientation="横">

        <ImageView
            android:id="@+id/m1"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            アンドロイド:layout_weight="1"
            android:src="@drawable/ylu" />

        <ImageView
            アンドロイド:layout_weight="1"
            android:id="@+id/m2"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/phbang" />
        <ImageView
            アンドロイド:layout_weight="1"
            アンドロイド:id="@+id/m3"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/flei" />
        <ImageView
            アンドロイド:layout_weight="1"
            アンドロイド:id="@+id/m4"
            Android:layout_width="wrap_content"
            Android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/cnxhuan" />

    </LinearLayout>
    <リストビュー
        android:background="@drawable/yybj1"
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

効果のスクリーンショットは次のとおりです。

 

 

おすすめ

転載: blog.csdn.net/Abtxr/article/details/126856942