GithubHelp home page GithubHelp logo

nazmulidris / android-simple-mediaplayer Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 22.0 800 KB

Sample code that shows how to use the basics of the Android MediaPlayer class.

License: Apache License 2.0

Java 100.00%

android-simple-mediaplayer's Issues

Propose Logo/Icon

Hi @nazmulidris . I'm graphic disigner. I would like to know if you are interested that I make a logo for your project? If you allowed me, i"ll make logo for your project for free.

Best Regard
Mirza Zulfan

My App does not read .mp3 files from SD Card

Here are my MainActivity.java codes but it does not read the .mp3 files from the SD card.

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import com.musicPlayer.patel.lastkingmusicplayer.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

ListView myListViewForSongs;
String[] items;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myListViewForSongs = (ListView) findViewById(R.id.mySongListView);


    MultiplePermissionsListener();

}






public void MultiplePermissionsListener() {

    Dexter.withActivity(this)
            .withPermissions(
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                   )
            .withListener(new MultiplePermissionsListener() {
                @Override
                public void onPermissionsChecked(MultiplePermissionsReport report) {
                    // check if all permissions are granted
                    if (report.areAllPermissionsGranted()) {
                        // do you work now
                        display();
                    }

                    // check for permanent denial of any permission
                    if (report.isAnyPermissionPermanentlyDenied()) {
                        // permission is denied permanently, navigate user to app settings
                    }
                }

                @Override
                public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
                    token.continuePermissionRequest();
                }
            }).check();
}



public ArrayList<File> findSong(File file) {

    ArrayList<File> arrayList = new ArrayList<>();

    File [] files = file.listFiles();

    for (File singleFile: files) {

        if(singleFile.isDirectory() && !singleFile.isHidden()){

            arrayList.addAll(findSong(singleFile));
        }
        else {
            if (singleFile.getName().endsWith(".mp3") ||
                    singleFile.getName().endsWith(".wav")) {

                arrayList.add(singleFile);
            }
        }
    }

    return arrayList;
}

void display(){

    final ArrayList<File> mySongs = findSong(Environment.getExternalStorageDirectory());

    items = new String[mySongs.size()];

    for (int i=0;i<mySongs.size();i++) {

        items[i] = mySongs.get(i).getName().toString().replace(".mp3","").replace(".wav","");

    }

    ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,items);
    myListViewForSongs.setAdapter(myAdapter);

    myListViewForSongs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int i, long l) {

            String songName = myListViewForSongs.getItemAtPosition(i).toString();

            startActivity(new Intent(getApplicationContext(),PlayerActivity.class)
                    .putExtra("songs",mySongs).putExtra("songname",songName)
                    .putExtra("pos",i));


        }
    });




}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.