@F_Dehghan
خدا خیرت بده .... خیلی آقایی
بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
مدیریت گفتگو
پاسخها 1
توی فرگمنت صفحه هامو ساختم و زمانی که play کلیک میشه گفتم اگر فایل موجوده بخون اگرنه دانلود کن
public void play(View view) {
position = myPager.getCurrentItem();
if (new File(G.DIR_FINAL + "/" + mAudio[position]).exists()) {
mp = MediaPlayer.create(G.context, Uri.parse(G.DIR_FINAL + "/" + mAudio[position]));
Toast.makeText(G.context, R.string.playing, Toast.LENGTH_LONG).show();
if (mp != null && !mp.isPlaying()) {
mp.start();
finalTime = mp.getDuration();
startTime = mp.getCurrentPosition();
if (oneTimeOnly == 0) {
seekbar.setMax((int) finalTime);
oneTimeOnly = 1;
}
endTimeField.setText(String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) / 60,
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) % 60)
);
startTimeField.setText(String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toSeconds((long) startTime) / 60,
TimeUnit.MILLISECONDS.toSeconds((long) startTime) % 60)
);
seekbar.setProgress((int) startTime);
myHandler.postDelayed(UpdateSongTime, 100);
pauseButton.setEnabled(true);
playButton.setEnabled(false);
}
}
else {
filename = mAudio[myPager.getCurrentItem()];
d = new AlertDialog.Builder(this)
.setTitle(R.string.download)
.setMessage(R.string.message)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(G.context, R.string.downloading, Toast.LENGTH_LONG).show();
rlPrg.setVisibility(View.VISIBLE);
playButton.setEnabled(false);
seekbar.setVisibility(View.GONE);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
startDownload("آدرس پوشه حاوی موزیک ها در سرور/" + filename, G.DIR_FINAL + "/" + filename, prgDownloadProgress, txtPercent);
}
});
thread.start();
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.setIcon(R.drawable.download)
.show();
Resources res = G.context.getResources();
TextView messageView = (TextView) ((Dialog) d).findViewById(android.R.id.message);
messageView.setTextColor(res.getColor(R.color.white));
final int titleId = res.getIdentifier("alertTitle", "id", "android");
final View title = ((Dialog) d).findViewById(titleId);
if (title != null) {
((TextView) title).setTextColor(res.getColor(R.color.white));
}
final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
final View titleDivider = ((Dialog) d).findViewById(titleDividerId);
if (titleDivider != null) {
titleDivider.setBackgroundColor(res.getColor(R.color.white));
}
}
}
private void startDownload(final String downloadURL, final String filePath
, final ProgressBar prgDownloadProgress
, final TextView txtPercent) {
ModuleDownloader downloadRequest = new ModuleDownloader();
OnProgressDownloadListener progressListener = new OnProgressDownloadListener() {
@Override
public void onProgressDownload(final int percent, final int downloadedSize, final int fileSize) {
G.HANDLER.post(new Runnable() {
@Override
public void run() {
Drawable draw = getResources().getDrawable(R.drawable.costum_progress);
prgDownloadProgress.setProgressDrawable(draw);
prgDownloadProgress.setProgress(percent);
txtPercent.setText(percent + " % ");
}
});
}
};
OnDownloadCompleteListener completeListener = new OnDownloadCompleteListener() {
@Override
public void OnDownloadComplete(final String filepath) {
G.HANDLER.post(new Runnable() {
@Override
public void run() {
rlPrg.setVisibility(View.GONE);
pauseButton.setEnabled(false);
playButton.setEnabled(true);
seekbar.setVisibility(View.VISIBLE);
play(playButton);
}
});
}
};
downloadRequest.downloadPath(downloadURL)
.filepath(filePath)
.simulate(true)
.progressListener(progressListener)
.completeListener(completeListener);
downloadRequest.download();
}
متاسفانه خیلی تمیز نیست .ببخشید .ببینید مشکلتونو حل میکنه؟
نظرات
خواهش میکنم.امیدوارم کمک کرده باشه .چون خودم تقریبا دو ماهی گرفتارش بودم D: موفق باشید (:
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات