Open bogger98 opened 9 months ago
thnaks for great library in case it is of use to anyone this is simle implementation using just java
public MediaPlayer mediaPlayer; BarVisualizer barVisualizer; RelativeLayout rel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); rel=new RelativeLayout(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED) { // put your code for Version>=Marshmallow } else { if (shouldShowRequestPermissionRationale(Manifest.permission.RECORD_AUDIO)) { Toast.makeText(this, "App required access to audio", Toast.LENGTH_SHORT).show(); } requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO }, 100); } } else { // will do later } mediaPlayer = MediaPlayer.create(this, R.raw.sample); mediaPlayer.start(); int id= mediaPlayer.getAudioSessionId(); if (id !=-1){ System.out.println("aaaaaaaaaaaaaa "+id); barVisualizer=new BarVisualizer(this); barVisualizer.setPlayer(id);//(mediaPlayer.getAudioSessionId()); barVisualizer.setVisibility(View.VISIBLE); barVisualizer.setColor(Color.RED); barVisualizer.setDensity(80); rel.addView(barVisualizer); System.out.println("bbbbbbbbbbbbbb "+id); }else{ System.out.println("mediaplay id is null"); } setContentView(rel); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == 101) { if (grantResults[0] != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getApplicationContext(), " record", Toast.LENGTH_SHORT).show(); } } } }
thnaks for great library in case it is of use to anyone this is simle implementation using just java