خلاصه نویسی های برنامه نویسی اندروید



package ir.ben.frog;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;

import java.util.Timer;
import java.util.TimerTask;

public class audplayer extends AppCompatActivity implements View.OnClickListener {
    MediaPlayer mp;
    SeekBar volbar,scroll;
    AudioManager mang;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audplayer);
        volbar =findViewById(R.id.seekBar);
        scroll=findViewById(R.id.scroll);
        mp= MediaPlayer.create(this,R.raw.demoaudio);

        //////Audio manager
        mang= (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        int maxvol=mang.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        int curvol=mang.getStreamVolume(AudioManager.STREAM_MUSIC);

        scroll.setMax(mp.getDuration());
        scroll.setProgress(0);
        new Timer().scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                scroll.setProgress(mp.getCurrentPosition());

            }
        },0,100);

        scroll.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if(mp!=null && fromUser)
                mp.seekTo(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        volbar.setMax(maxvol);
        volbar.setProgress(curvol);


        mp.start();

        volbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                mang.setStreamVolume(AudioManager.STREAM_MUSIC,progress,0);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

    }

    @Override
    public void onClick(View v) {

    }
}

 


آخرین جستجو ها