2 Комити b90dcb7e78 ... a3075018d3

Аутор SHA1 Порука Датум
  房丽婷 a3075018d3 music пре 3 година
  房丽婷 c6fd0f6dc4 decorate пре 3 година

BIN
app/src/main/assets/AlienBoi - 雾霾(免费下载).flac


BIN
app/src/main/assets/G23 - [免费]The Gifted.mp3


BIN
app/src/main/assets/ZC - 【免费可商用】“HEY GIRL”真的不写首歌给她?CHILL/RNB/TRAP BEAT.flac


+ 3 - 1
app/src/main/java/com/example/mymusic/CellPrototypeInterface.java

@@ -1,5 +1,7 @@
 package com.example.mymusic;
 
 public interface CellPrototypeInterface {
-    void cellClicked(Music music);
+
+    void cellClicked(String toString, int adapterPosition);
+
 }

+ 8 - 13
app/src/main/java/com/example/mymusic/MainActivity.java

@@ -4,6 +4,8 @@ import androidx.appcompat.app.AppCompatActivity;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
 import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.util.Log;
@@ -89,7 +91,12 @@ public class MainActivity extends AppCompatActivity {
                 Log.v(TAG,"START");
                 mediaPlayer.reset();            //初始化
 
-                mediaPlayer.setDataSource("assets");    //设置播放源
+                AssetManager assetManager = getAssets();
+                AssetFileDescriptor assetFileDescriptor = assetManager.openFd("AlienBoi - 雾霾(免费下载)");
+                mediaPlayer.setDataSource(
+                        assetFileDescriptor.getFileDescriptor(),
+                        assetFileDescriptor.getStartOffset(),
+                        assetFileDescriptor.getLength());    //设置播放源
 
                 mediaPlayer.prepare();          //准备播放
                 mediaPlayer.start();            //开始播放
@@ -103,18 +110,6 @@ public class MainActivity extends AppCompatActivity {
             }
         });
 
-        /*
-        btnStop.setOnClickListener(view -> {
-            if(mediaPlayer.isPlaying()){
-                btnStop.setText("play");
-                mediaPlayer.pause();
-            } else {
-                btnStop.setText("stop");
-                mediaPlayer.start();
-            }
-        });
-        */
-
         btnStop.setOnClickListener(view -> {
             if(mediaPlayer.isPlaying()){
                 mediaPlayer.stop();

+ 5 - 2
app/src/main/java/com/example/mymusic/Music.java

@@ -6,9 +6,12 @@ import android.widget.TextView;
 import androidx.recyclerview.widget.RecyclerView;
 
 public class Music {
+
     String musicName;
+    int musicPosition;
 
-    public Music(String musicName){
-        this.musicName = musicName;
+    public Music(String name,int position){
+        this.musicName = name;
+        this.musicPosition = position;
     }
 }

+ 19 - 3
app/src/main/java/com/example/mymusic/MusicAdapter.java

@@ -10,6 +10,8 @@ import android.widget.TextView;
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.RecyclerView;
 
+import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.ViewHolder> implements CellPrototypeInterface{
@@ -17,11 +19,19 @@ public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.ViewHolder>
     List<Music> musicList;
     CellPrototypeInterface cellPrototypeInterface;
 
+    /*
     @Override
     public void cellClicked(Music music) {
         cellPrototypeInterface.cellClicked(music);
         notifyDataSetChanged();
     }
+     */
+
+    @Override
+    public void cellClicked(String name, int adapterPosition) {
+        cellPrototypeInterface.cellClicked(name, adapterPosition);
+        notifyDataSetChanged();
+    }
 
     class ViewHolder extends RecyclerView.ViewHolder{
 
@@ -29,12 +39,17 @@ public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.ViewHolder>
 
         public ViewHolder(View itemView) {
             super(itemView);
-            View musicName = itemView.findViewById(R.id.cell);
+            Name = itemView.findViewById(R.id.cell);
+            Name.setOnClickListener(view -> {
+                cellPrototypeInterface.cellClicked(Name.getText().toString(),getAdapterPosition());
+            });
         }
     }
 
-    public MusicAdapter(List<Music> musicList1){
-        musicList = musicList1;
+    public MusicAdapter(CellPrototypeInterface cellPrototypeInterface1){
+        musicList = new ArrayList<>();
+        this.cellPrototypeInterface = cellPrototypeInterface1;
+        File file = new File("/assets");
     }
 
     @NonNull
@@ -42,6 +57,7 @@ public class MusicAdapter extends RecyclerView.Adapter<MusicAdapter.ViewHolder>
     public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
         View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cell,parent,false);
         ViewHolder viewHolder = new ViewHolder(view);
+        //CellPrototypeInterface prototypeInterface = new CellPrototypeInterface(view) ;
         return viewHolder;
     }
 

+ 1 - 0
app/src/main/res/layout/activity_main.xml

@@ -16,6 +16,7 @@
         app:layout_constraintTop_toTopOf="parent">
 
         <LinearLayout
+            android:id="@+id/LinearLayout"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="3"