nazmulidris / android-simple-mediaplayer Goto Github PK
View Code? Open in Web Editor NEWSample code that shows how to use the basics of the Android MediaPlayer class.
License: Apache License 2.0
Sample code that shows how to use the basics of the Android MediaPlayer class.
License: Apache License 2.0
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
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));
}
});
}
App crash when app in background
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.