بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
دانلود آهنگ از سرور و پخش در موزیک پلیر (( استاد کمک کن ))
درود
استاد تورو خدا کمکم کنید ..
چند ماهه که من سر این دانلود موندم
من چطوری باید آهنگ رو از سرور دانلود کنم؟؟
توو مرور گر آدرس لینک رو که میدم دانلود میشه اما توو اندروید دانلود نمیشه ...
سوال بعدی این که و قتی دانلود شد چوری باید با موزیک پلیر پخش شه ....
ی قسمت ی دکمه ی Download_music قرار دادم . با زدن این دکمه آهنگ باید دانلود شه .. کمکم کنید
public class ActivityMusicDetail extends EnhancedActivity implements OnCompletionListener, SeekBar.OnSeekBarChangeListener {
private MediaPlayer mediaPlayer;
private int seekForwardTime = 3000;
private int seekBackwardTime = 3000;
private double timeElapsed = 0;
private SeekBar songProgressBar;
private Button btnPlay;
private Button btnForward;
private Button btnBackward;
private TextView songCurrentDurationLabel;
private TextView songTotalDurationLabel;
private Utilities utils;
public static int oneTimeOnly = 0;
private int currentSongIndex = 0;
private TextView music_name;
private TextView singer_name;
private Button btnBack;
private Button Download_music;
private ImageView imgLogo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_detail);
music_name = (TextView) findViewById(R.id.music_name);
singer_name = (TextView) findViewById(R.id.singer_name);
btnBack = (Button) findViewById(R.id.btnBack);
Download_music = (Button) findViewById(R.id.Download_music);
imgLogo = (ImageView) findViewById(R.id.imgLogo);
btnPlay = (Button) findViewById(R.id.btnPlay);
btnForward = (Button) findViewById(R.id.btnForward);
btnBackward = (Button) findViewById(R.id.btnBackward);
songProgressBar = (SeekBar) findViewById(R.id.songProgressBar);
songCurrentDurationLabel = (TextView) findViewById(R.id.songCurrentDurationLabel);
songTotalDurationLabel = (TextView) findViewById(R.id.songTotalDurationLabel);
mediaPlayer = new MediaPlayer();
mediaPlayer = MediaPlayer.create(this, R.raw.sample_song);
utils = new Utilities();
songProgressBar.setClickable(false);
songProgressBar.setOnSeekBarChangeListener(this);
mediaPlayer.setOnCompletionListener(this);
songProgressBar.setProgress(oneTimeOnly);
music_name.setText(G.selectedApplication.music_name);
singer_name.setText(G.selectedApplication.singer_name);
Download_music.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String musicname = HelperString.getFileName(G.selectedApplication.music_downloadUrl);
DownloadRequest downloadRequest = new DownloadRequest()
.downloadPath("http://169.254.72.1/Folkolor/" + G.selectedApplication.music_downloadUrl)
.filepath(G.DIR_MUSIC + "/" + musicname)
.listener(new OnDownloadCompleteListener() {
@Override
public void onDownloadComplete(String url, String localPath) {
}
})
.download();
}
});
String filename = HelperString.getFileName(G.selectedApplication.logoUrl);
final File imageFile = new File(G.DIR_FINAL + "/" + filename);
if ( !imageFile.exists()) {
imgLogo.setImageBitmap(null);
DownloadManager.addToDownloadList(G.selectedApplication.logoUrl, imgLogo);
}
BitmapFactory.Options options = new BitmapFactory.Options();
//options.inSampleSize = 8;
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), options);
imgLogo.setImageBitmap(bitmap);
btnBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(G.currentActivity, ActivityMusicsList.class);
G.currentActivity.startActivity(intent);
G.currentActivity.finish();
}
});
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// check for already playing
if (mediaPlayer.isPlaying()) {
if (mediaPlayer != null) {
mediaPlayer.pause();
// Changing button image to play button
btnPlay.setBackgroundResource(R.drawable.play);
}
} else {
// Resume song
if (mediaPlayer != null) {
mediaPlayer.start();
timeElapsed = mediaPlayer.getCurrentPosition();
songProgressBar.setProgress((int) timeElapsed);
G.HANDLER.postDelayed(mUpdateTimeTask, 100);
btnPlay.setBackgroundResource(R.drawable.pause);
}
}
}
});
btnForward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// get current song position
int currentPosition = mediaPlayer.getCurrentPosition();
// check if seekForward time is lesser than song duration
if (currentPosition + seekForwardTime <= mediaPlayer.getDuration()) {
// forward song
mediaPlayer.seekTo(currentPosition + seekForwardTime);
} else {
// forward to end position
mediaPlayer.seekTo(mediaPlayer.getDuration());
}
}
});
/**
* Backward button click event
* Backward song to specified seconds
* */
btnBackward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// get current song position
int currentPosition = mediaPlayer.getCurrentPosition();
// check if seekBackward time is greater than 0 sec
if (currentPosition - seekBackwardTime >= 0) {
// forward song
mediaPlayer.seekTo(currentPosition - seekBackwardTime);
} else {
// backward to starting position
mediaPlayer.seekTo(0);
}
}
});
}
public void playSong(int songIndex) {
// Play song
try {
mediaPlayer.reset();
mediaPlayer.prepare();
mediaPlayer.start();
// Changing Button Image to pause image
btnPlay.setBackgroundResource(R.drawable.play);
// set Progress bar values
songProgressBar.setProgress(0);
songProgressBar.setMax(100);
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (IllegalStateException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
/**
* Update timer on seekbar
* */
public void updateProgressBar() {
G.HANDLER.postDelayed(mUpdateTimeTask, 100);
}
/**
* Background Runnable thread
* */
private Runnable mUpdateTimeTask = new Runnable() {
@Override
public void run() {
long totalDuration = mediaPlayer.getDuration();
long currentDuration = mediaPlayer.getCurrentPosition();
// Displaying Total Duration time
songTotalDurationLabel.setText("" + utils.milliSecondsToTimer(totalDuration));
// Displaying time completed playing
songCurrentDurationLabel.setText("" + utils.milliSecondsToTimer(currentDuration));
// Updating progress bar
int progress = (int) (utils.getProgressPercentage(currentDuration, totalDuration));
//Log.d("Progress", ""+progress);
songProgressBar.setProgress(progress);
// Running this thread after 100 milliseconds
G.HANDLER.postDelayed(this, 100);
}
};
/**
*
* */
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
}
/**
* When user starts moving the progress handler
* */
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// remove message Handler from updating progress bar
G.HANDLER.removeCallbacks(mUpdateTimeTask);
}
/**
* When user stops moving the progress hanlder
* */
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
G.HANDLER.removeCallbacks(mUpdateTimeTask);
int totalDuration = mediaPlayer.getDuration();
int currentPosition = utils.progressToTimer(seekBar.getProgress(), totalDuration);
// forward or backward to certain seconds
mediaPlayer.seekTo(currentPosition);
// update timer progress again
updateProgressBar();
}
@Override
public void onDestroy() {
super.onDestroy();
mediaPlayer.pause();
}
@Override
public void onCompletion(MediaPlayer arg0) {
btnPlay.setBackgroundResource(R.drawable.play);
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
ba2ever
11 سال پیش
0
0
واقعا کسی نیست که کمکم کنه..........؟؟؟؟؟؟؟؟؟؟
استاااااااااااااااااااااااااااااااااااااااااااااد ؟؟؟؟؟ خواهش میکنم کمکم کنید .........
چیز بعدی که به ذهنم میرسه : یک log از این خطی که اسم موزیک رو میده G.selectedApplication.music_downloadUrl بگیرید و اونو در براوزرتون در ادامه این آدرس لینک وارد کنید ببینید به فایل میرسه یا نه؟ (11 سال پیش)
لینک (11 سال پیش)
@F_Dehghan
مرسی . راسش اون لینک اولتون رو که توو مرورگر میزنم بم لینک دانلود میده مشکلی در این جا نیست. اما از لینک دومتون سر در نیائردم و یعنی نمیدونم که کجا باس ازین استفاده کنم . راسش طاهر برنامه ی من شبیه برنامه ی مارکت هست یعنی بعا=د ازین که ی اسپلش اومد و رفت بعدش یک لیستی از آنگا مید و این بخش مدیا پلیر دقیقا میشه ctivity detail توو پروژه ی مارکت .. این کدی که شما نوشتی رو من باس کجا بزارم ؟؟ در ضمن اون عکسی که از استاد شجریان گذاشتم رو از نت داره میخونه .که دقیقا شبیه پروژه ی مارکت هس .. این عکس ها برای خودش یک download mangaer داره .. آیا من باید برای دانلود موزیک ی download manager دیگه درست کنم ؟؟ این کد شما در کجا باس قرار بگیره :(
(11 سال پیش)
نمونه کد رو توی این پست قرار دادم لینک لینک (11 سال پیش)
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
