Java 获取logcat错误:E/ExtMediaPlayer JNI:env->;IsInstanceOf失败

Java 获取logcat错误:E/ExtMediaPlayer JNI:env->;IsInstanceOf失败,java,android,xml,user-interface,albumart,Java,Android,Xml,User Interface,Albumart,我正在尝试为我的音乐播放器应用程序中的每首歌曲获取专辑艺术。但是除了黑屏,没有专辑封面,我什么也没有得到。代码中似乎没有类似的错误,除了我从未听说过的log cat错误 下面是Java文件,其中包含按钮单击的侦听器。我一单击应用程序中的按钮,logcat中就会出现错误:Bacon1.java import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; impor

我正在尝试为我的音乐播放器应用程序中的每首歌曲获取专辑艺术。但是除了黑屏,没有专辑封面,我什么也没有得到。代码中似乎没有类似的错误,除了我从未听说过的log cat错误

下面是Java文件,其中包含按钮单击的侦听器。我一单击应用程序中的按钮,logcat中就会出现错误:Bacon1.java

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;


public class Bacon1 extends Activity {

    private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
    private static int RESULT_LOAD_IMAGE = 1;
    public ArrayList<HashMap<String, String>> songsList = new ArrayList<>();

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


        Button button4 = (Button) findViewById(R.id.button4);

        button4.setOnClickListener(
                new Button.OnClickListener()

                {
                    public void onClick(View v) {
                        buttonClicked(v);

                       Intent p = new Intent(Bacon1.this,PlayListActivity.class);
                        startActivity(p);

                    }
                });
    }

    private void buttonClicked(View view) {

        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_EXTERNAL_STORAGE) + ContextCompat
                .checkSelfPermission(this,
                        Manifest.permission.INTERNET)
                != PackageManager.PERMISSION_GRANTED) {

            Snackbar.make(view, "Permission not Granted, Requesting permission.", Snackbar.LENGTH_LONG).show();
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {

                Snackbar.make(view, "We need permission to internal storage for displaying songs", Snackbar.LENGTH_LONG).show();

            } else {

                Snackbar.make(view, "Allow myapp3 to access this device's internal storage", Snackbar.LENGTH_LONG).show();

                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                        MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

                // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }
        }


    }


    public void onClick2(View view) {

        Intent i = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(i, RESULT_LOAD_IMAGE);
    }


    public void onClick4(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "video/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick5(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "zip/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick6(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "text/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick7(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "application/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case 1: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(Bacon1.this, "WRITE_CONTACTS granted", Toast.LENGTH_SHORT)
                            .show();




                } else {

                    Toast.makeText(Bacon1.this, "WRITE_CONTACTS Denied", Toast.LENGTH_SHORT)
                            .show();

                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }


    }
package com.example.dell_1.myapp3;


import android.app.Activity;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import java.io.File;
import java.io.IOException;

import com.bumptech.glide.Glide;


public class PlayListActivity extends Activity {

    private String[] mAudioPath;
    private MediaPlayer mMediaPlayer;
    private String[] mMusicList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_list);

        mMediaPlayer = new MediaPlayer();
        ListView mListView = (ListView) findViewById(R.id.list);

        mMusicList = getAudioList();

        ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, mMusicList);
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int arg2,
                                    long arg3) {

                try {
                    playSong(mAudioPath[arg2]);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    private String[] getAudioList() {
        final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA}, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];
        mAudioPath = new String[count];
        int i = 0;
        if (mCursor.moveToFirst()) {
            do {
                songs[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
                mAudioPath[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                i++;
            } while (mCursor.moveToNext());
        }

        mCursor.close();

        return songs;
    }

    private void playSong(String path) throws IllegalArgumentException,
            IllegalStateException, IOException {

        setContentView(R.layout.activity_android_building_music_player);
        Log.d("ringtone", "playSong :: " + path);

        mMediaPlayer.reset();
        mMediaPlayer.setDataSource(path);
//mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();

        asd();

    }

    public void asd() {
        ImageView imageView = (ImageView) findViewById(R.id.coverart);


        File music = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        // Tested with music from Windows 7's c:\Users\Public\Music\Sample Music
        String filePath = new File(music, "I love you.mp3").getAbsolutePath();
        Glide
                .with(this)
                .load(new AudioCover(filePath))
                .placeholder(R.drawable.adele1)
                .error(R.drawable.adele1)
                .into(imageView);
    }
}
 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:divider="#242424"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

    </LinearLayout>

**activity_android_building_music_player.xml** :  

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:id="@+id/player_header_bg"
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:layout_alignParentTop="true"
        android:background="@layout/bg_player_header"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">

        <TextView
            android:id="@+id/songTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:paddingLeft="50dp"
            android:text="The Good, The Bad And The Ugly"
            android:textColor="#04b3d2"
            android:textSize="16dp"
            android:textStyle="bold" />

        <ImageButton
            android:id="@+id/btnPlaylist"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:background="@null"
            android:src="@drawable/btn_playlist" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/songThumbnail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/player_header_bg"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp">

        <ImageView
            android:id="@+id/coverart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/player_footer_bg"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@layout/bg_player_footer"
        android:gravity="center">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:weightSum="1">
            <RelativeLayout
                android:layout_width="300dp"
                android:layout_height="match_parent">
                <ImageButton
                    android:id="@+id/btnPrevious"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.40"
                    android:layout_alignParentLeft="true"
                    android:paddingLeft="10dp"
                    android:background="@null"
                    android:src="@drawable/btn_previous" />

                <ImageButton
                    android:id="@+id/btnPlay1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@null"
                    android:src="@drawable/btn_play"
                    android:onClick="buttonAction1"/>


                <ImageButton
                    android:id="@+id/btnNext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="250dp"
                    android:background="@null"
                    android:src="@drawable/btn_next" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

    <SeekBar
        android:id="@+id/songProgressBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/player_footer_bg"
        android:layout_alignLeft="@+id/timerDisplay"
        android:layout_alignStart="@+id/timerDisplay"
        android:layout_marginBottom="10dp"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:progressDrawable="@drawable/seekbar_progress"
        android:thumb="@drawable/download8" />

    <LinearLayout
        android:id="@+id/timerDisplay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/songProgressBar"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <TextView
            android:id="@+id/songCurrentDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:textColor="#eeeeee"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/songTotalDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textColor="#04cbde"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/timerDisplay"
        android:gravity="center">

        <ImageButton
            android:id="@+id/btnRepeat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:background="@null"
            android:src="@drawable/btn_repeat" />

        <ImageButton
            android:id="@+id/btnShuffle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:background="@null"
            android:src="@drawable/btn_shuffle" />
    </LinearLayout>
</RelativeLayout>
以下是负责将歌曲显示为listview的文件:playlayActivity.java

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;


public class Bacon1 extends Activity {

    private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
    private static int RESULT_LOAD_IMAGE = 1;
    public ArrayList<HashMap<String, String>> songsList = new ArrayList<>();

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


        Button button4 = (Button) findViewById(R.id.button4);

        button4.setOnClickListener(
                new Button.OnClickListener()

                {
                    public void onClick(View v) {
                        buttonClicked(v);

                       Intent p = new Intent(Bacon1.this,PlayListActivity.class);
                        startActivity(p);

                    }
                });
    }

    private void buttonClicked(View view) {

        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_EXTERNAL_STORAGE) + ContextCompat
                .checkSelfPermission(this,
                        Manifest.permission.INTERNET)
                != PackageManager.PERMISSION_GRANTED) {

            Snackbar.make(view, "Permission not Granted, Requesting permission.", Snackbar.LENGTH_LONG).show();
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {

                Snackbar.make(view, "We need permission to internal storage for displaying songs", Snackbar.LENGTH_LONG).show();

            } else {

                Snackbar.make(view, "Allow myapp3 to access this device's internal storage", Snackbar.LENGTH_LONG).show();

                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                        MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

                // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }
        }


    }


    public void onClick2(View view) {

        Intent i = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(i, RESULT_LOAD_IMAGE);
    }


    public void onClick4(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "video/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick5(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "zip/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick6(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "text/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick7(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "application/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case 1: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(Bacon1.this, "WRITE_CONTACTS granted", Toast.LENGTH_SHORT)
                            .show();




                } else {

                    Toast.makeText(Bacon1.this, "WRITE_CONTACTS Denied", Toast.LENGTH_SHORT)
                            .show();

                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }


    }
package com.example.dell_1.myapp3;


import android.app.Activity;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import java.io.File;
import java.io.IOException;

import com.bumptech.glide.Glide;


public class PlayListActivity extends Activity {

    private String[] mAudioPath;
    private MediaPlayer mMediaPlayer;
    private String[] mMusicList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_list);

        mMediaPlayer = new MediaPlayer();
        ListView mListView = (ListView) findViewById(R.id.list);

        mMusicList = getAudioList();

        ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, mMusicList);
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int arg2,
                                    long arg3) {

                try {
                    playSong(mAudioPath[arg2]);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    private String[] getAudioList() {
        final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA}, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];
        mAudioPath = new String[count];
        int i = 0;
        if (mCursor.moveToFirst()) {
            do {
                songs[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
                mAudioPath[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                i++;
            } while (mCursor.moveToNext());
        }

        mCursor.close();

        return songs;
    }

    private void playSong(String path) throws IllegalArgumentException,
            IllegalStateException, IOException {

        setContentView(R.layout.activity_android_building_music_player);
        Log.d("ringtone", "playSong :: " + path);

        mMediaPlayer.reset();
        mMediaPlayer.setDataSource(path);
//mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();

        asd();

    }

    public void asd() {
        ImageView imageView = (ImageView) findViewById(R.id.coverart);


        File music = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        // Tested with music from Windows 7's c:\Users\Public\Music\Sample Music
        String filePath = new File(music, "I love you.mp3").getAbsolutePath();
        Glide
                .with(this)
                .load(new AudioCover(filePath))
                .placeholder(R.drawable.adele1)
                .error(R.drawable.adele1)
                .into(imageView);
    }
}
 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:divider="#242424"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

    </LinearLayout>

**activity_android_building_music_player.xml** :  

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:id="@+id/player_header_bg"
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:layout_alignParentTop="true"
        android:background="@layout/bg_player_header"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">

        <TextView
            android:id="@+id/songTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:paddingLeft="50dp"
            android:text="The Good, The Bad And The Ugly"
            android:textColor="#04b3d2"
            android:textSize="16dp"
            android:textStyle="bold" />

        <ImageButton
            android:id="@+id/btnPlaylist"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:background="@null"
            android:src="@drawable/btn_playlist" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/songThumbnail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/player_header_bg"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp">

        <ImageView
            android:id="@+id/coverart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/player_footer_bg"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@layout/bg_player_footer"
        android:gravity="center">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:weightSum="1">
            <RelativeLayout
                android:layout_width="300dp"
                android:layout_height="match_parent">
                <ImageButton
                    android:id="@+id/btnPrevious"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.40"
                    android:layout_alignParentLeft="true"
                    android:paddingLeft="10dp"
                    android:background="@null"
                    android:src="@drawable/btn_previous" />

                <ImageButton
                    android:id="@+id/btnPlay1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@null"
                    android:src="@drawable/btn_play"
                    android:onClick="buttonAction1"/>


                <ImageButton
                    android:id="@+id/btnNext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="250dp"
                    android:background="@null"
                    android:src="@drawable/btn_next" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

    <SeekBar
        android:id="@+id/songProgressBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/player_footer_bg"
        android:layout_alignLeft="@+id/timerDisplay"
        android:layout_alignStart="@+id/timerDisplay"
        android:layout_marginBottom="10dp"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:progressDrawable="@drawable/seekbar_progress"
        android:thumb="@drawable/download8" />

    <LinearLayout
        android:id="@+id/timerDisplay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/songProgressBar"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <TextView
            android:id="@+id/songCurrentDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:textColor="#eeeeee"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/songTotalDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textColor="#04cbde"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/timerDisplay"
        android:gravity="center">

        <ImageButton
            android:id="@+id/btnRepeat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:background="@null"
            android:src="@drawable/btn_repeat" />

        <ImageButton
            android:id="@+id/btnShuffle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:background="@null"
            android:src="@drawable/btn_shuffle" />
    </LinearLayout>
</RelativeLayout>
package com.example.dell_1.myapp3;
导入android.app.Activity;
导入android.database.Cursor;
导入android.media.MediaPlayer;
导入android.os.Bundle;
导入android.os.Environment;
导入android.provider.MediaStore;
导入android.util.Log;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.ImageView;
导入android.widget.ListView;
导入java.io.File;
导入java.io.IOException;
导入com.bumptech.glide.glide;
公共类活动扩展了活动{
私有字符串[]路径;
私有媒体层;
私有字符串[]mMusicList;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u play\u list);
mMediaPlayer=新媒体播放器();
ListView mListView=(ListView)findViewById(R.id.list);
mMusicList=getAudioList();
ArrayAdapter mAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,mMusicList);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView arg0、View视图、int arg2、,
长arg3){
试一试{
playSong(mAudioPath[arg2]);
}捕获(IllegalArgumentException e){
e、 printStackTrace();
}捕获(非法状态){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}
});
}
私有字符串[]getAudioList(){
最终游标mCursor=getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL\u CONTENT\u URI,
新字符串[]{MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Audio.Media.DATA},null,null,
“下(“+MediaStore.Audio.Media.TITLE+”)ASC”);
int count=mCursor.getCount();
字符串[]歌曲=新字符串[计数];
mAudioPath=新字符串[计数];
int i=0;
if(mCursor.moveToFirst()){
做{
songs[i]=mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
mAudioPath[i]=mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
i++;
}while(mCursor.moveToNext());
}
mCursor.close();
返回歌曲;
}
私有void playSong(字符串路径)抛出IllegalArgumentException,
IlegalStateException,IOException{
setContentView(R.layout.activity\u android\u building\u music\u player);
Log.d(“铃声”,“播放歌曲::”+path);
mmediplayer.reset();
mmediplayer.setDataSource(路径);
//mmediplayer.setLooping(true);
mmediplayer.prepare();
mmediplayer.start();
asd();
}
公共建筑署(){
ImageView ImageView=(ImageView)findViewById(R.id.coverart);
文件music=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY\u music);
//使用Windows 7的c:\Users\Public\music\Sample music中的音乐进行测试
String filePath=新文件(音乐“I love you.mp3”).getAbsolutePath();
滑翔
.与(此)
.load(新的AudioCover(文件路径))
.占位符(R.drawable.adele1)
.错误(R.drawable.adele1)
.进入(图像视图);
}
}
这是xml文件:activity\u play\u list.xml

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;


public class Bacon1 extends Activity {

    private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
    private static int RESULT_LOAD_IMAGE = 1;
    public ArrayList<HashMap<String, String>> songsList = new ArrayList<>();

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


        Button button4 = (Button) findViewById(R.id.button4);

        button4.setOnClickListener(
                new Button.OnClickListener()

                {
                    public void onClick(View v) {
                        buttonClicked(v);

                       Intent p = new Intent(Bacon1.this,PlayListActivity.class);
                        startActivity(p);

                    }
                });
    }

    private void buttonClicked(View view) {

        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.READ_EXTERNAL_STORAGE) + ContextCompat
                .checkSelfPermission(this,
                        Manifest.permission.INTERNET)
                != PackageManager.PERMISSION_GRANTED) {

            Snackbar.make(view, "Permission not Granted, Requesting permission.", Snackbar.LENGTH_LONG).show();
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE)) {

                Snackbar.make(view, "We need permission to internal storage for displaying songs", Snackbar.LENGTH_LONG).show();

            } else {

                Snackbar.make(view, "Allow myapp3 to access this device's internal storage", Snackbar.LENGTH_LONG).show();

                ActivityCompat.requestPermissions(this,
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                        MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

                // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }
        }


    }


    public void onClick2(View view) {

        Intent i = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

        startActivityForResult(i, RESULT_LOAD_IMAGE);
    }


    public void onClick4(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "video/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick5(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "zip/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick6(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "text/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }

    public void onClick7(View view) {

        Intent viewIntent1 = new Intent(Intent.ACTION_VIEW);
        File file = Environment.getExternalStorageDirectory();
        viewIntent1.setDataAndType(Uri.fromFile(file), "application/*");
        startActivity(Intent.createChooser(viewIntent1, null));
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case 1: {
                // If request is cancelled, the result arrays are empty.
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(Bacon1.this, "WRITE_CONTACTS granted", Toast.LENGTH_SHORT)
                            .show();




                } else {

                    Toast.makeText(Bacon1.this, "WRITE_CONTACTS Denied", Toast.LENGTH_SHORT)
                            .show();

                }
                return;
            }

            // other 'case' lines to check for other
            // permissions this app might request
        }
    }


    }
package com.example.dell_1.myapp3;


import android.app.Activity;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import java.io.File;
import java.io.IOException;

import com.bumptech.glide.Glide;


public class PlayListActivity extends Activity {

    private String[] mAudioPath;
    private MediaPlayer mMediaPlayer;
    private String[] mMusicList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_list);

        mMediaPlayer = new MediaPlayer();
        ListView mListView = (ListView) findViewById(R.id.list);

        mMusicList = getAudioList();

        ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, mMusicList);
        mListView.setAdapter(mAdapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int arg2,
                                    long arg3) {

                try {
                    playSong(mAudioPath[arg2]);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    private String[] getAudioList() {
        final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA}, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];
        mAudioPath = new String[count];
        int i = 0;
        if (mCursor.moveToFirst()) {
            do {
                songs[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
                mAudioPath[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                i++;
            } while (mCursor.moveToNext());
        }

        mCursor.close();

        return songs;
    }

    private void playSong(String path) throws IllegalArgumentException,
            IllegalStateException, IOException {

        setContentView(R.layout.activity_android_building_music_player);
        Log.d("ringtone", "playSong :: " + path);

        mMediaPlayer.reset();
        mMediaPlayer.setDataSource(path);
//mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();

        asd();

    }

    public void asd() {
        ImageView imageView = (ImageView) findViewById(R.id.coverart);


        File music = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
        // Tested with music from Windows 7's c:\Users\Public\Music\Sample Music
        String filePath = new File(music, "I love you.mp3").getAbsolutePath();
        Glide
                .with(this)
                .load(new AudioCover(filePath))
                .placeholder(R.drawable.adele1)
                .error(R.drawable.adele1)
                .into(imageView);
    }
}
 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:divider="#242424"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector" />

    </LinearLayout>

**activity_android_building_music_player.xml** :  

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:id="@+id/player_header_bg"
        android:layout_width="fill_parent"
        android:layout_height="60dip"
        android:layout_alignParentTop="true"
        android:background="@layout/bg_player_header"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">

        <TextView
            android:id="@+id/songTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:paddingLeft="50dp"
            android:text="The Good, The Bad And The Ugly"
            android:textColor="#04b3d2"
            android:textSize="16dp"
            android:textStyle="bold" />

        <ImageButton
            android:id="@+id/btnPlaylist"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:background="@null"
            android:src="@drawable/btn_playlist" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/songThumbnail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/player_header_bg"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp">

        <ImageView
            android:id="@+id/coverart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/player_footer_bg"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@layout/bg_player_footer"
        android:gravity="center">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:weightSum="1">
            <RelativeLayout
                android:layout_width="300dp"
                android:layout_height="match_parent">
                <ImageButton
                    android:id="@+id/btnPrevious"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="2.40"
                    android:layout_alignParentLeft="true"
                    android:paddingLeft="10dp"
                    android:background="@null"
                    android:src="@drawable/btn_previous" />

                <ImageButton
                    android:id="@+id/btnPlay1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@null"
                    android:src="@drawable/btn_play"
                    android:onClick="buttonAction1"/>


                <ImageButton
                    android:id="@+id/btnNext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="250dp"
                    android:background="@null"
                    android:src="@drawable/btn_next" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

    <SeekBar
        android:id="@+id/songProgressBar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/player_footer_bg"
        android:layout_alignLeft="@+id/timerDisplay"
        android:layout_alignStart="@+id/timerDisplay"
        android:layout_marginBottom="10dp"
        android:paddingLeft="6dp"
        android:paddingRight="6dp"
        android:progressDrawable="@drawable/seekbar_progress"
        android:thumb="@drawable/download8" />

    <LinearLayout
        android:id="@+id/timerDisplay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/songProgressBar"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <TextView
            android:id="@+id/songCurrentDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:textColor="#eeeeee"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/songTotalDurationLabel"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:textColor="#04cbde"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/timerDisplay"
        android:gravity="center">

        <ImageButton
            android:id="@+id/btnRepeat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:background="@null"
            android:src="@drawable/btn_repeat" />

        <ImageButton
            android:id="@+id/btnShuffle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:background="@null"
            android:src="@drawable/btn_shuffle" />
    </LinearLayout>
</RelativeLayout>

**活动\u android\u building\u music\u player.xml**:

您是否解决了logcat错误问题?