Click here to Skip to main content
15,889,462 members
Home / Discussions / Android
   

Android

 
QuestionSQLite Database help Pin
Member 1185517022-Jul-15 3:58
Member 1185517022-Jul-15 3:58 
AnswerRe: SQLite Database help Pin
Richard MacCutchan22-Jul-15 6:22
mveRichard MacCutchan22-Jul-15 6:22 
GeneralRe: SQLite Database help Pin
Member 1185517022-Jul-15 6:31
Member 1185517022-Jul-15 6:31 
GeneralRe: SQLite Database help Pin
Richard MacCutchan22-Jul-15 7:37
mveRichard MacCutchan22-Jul-15 7:37 
GeneralRe: SQLite Database help Pin
Member 1185517022-Jul-15 8:47
Member 1185517022-Jul-15 8:47 
GeneralRe: SQLite Database help Pin
Richard MacCutchan22-Jul-15 21:08
mveRichard MacCutchan22-Jul-15 21:08 
SuggestionRe: SQLite Database help Pin
David Crow27-Jul-15 5:06
David Crow27-Jul-15 5:06 
Questionandroid listview display data in sdcard to top position in my listciew. Pin
ashish77309-Jul-15 19:17
ashish77309-Jul-15 19:17 
i want to print the litview music data to download file in the top of the listview online data can be display in below the download file please answer me.


package com.example.fununlimitedcopy;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.jar.Attributes.Name;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.OnScanCompletedListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

@SuppressLint("ViewHolder")
public class Tab1 extends Fragment implements OnClickListener,OnSeekBarChangeListener
{
private static final String TAG = null;
ListView list;
CustomAdaptor1 adapter;
private Tab1 activity;
public ArrayList<listmodel> CustomListViewValuesArr = new ArrayList<listmodel>();
private ArrayList<song> songList;
MediaPlayer mPlayer;
static Context ctx;
SeekBar seek_bar;
TextView start;
TextView total;
Button audio1;
Button gif1;
Button previous;
Button next;
Button playpause;
Handler seekHandler = new Handler();
int currentsongindex = 0;
Song songInfo = null;
int selPosition = -1;
int a = 1, b = 1;
boolean fristplay = false;
String activitystate = "empty";
ArrayList<musicdata> arrSongList; // three filds are show.
private static String folderPath = "";
String songpath;
String musicurl = "http://exporterp.in/vm/songs/";
int count;
String fileOutput;
ArrayList<string> sdcard = null;
boolean btndisplay;
boolean posting;
AlertDialog alertDialog ;
String StorePath;
public Tab1(Context c)
{
// TODO Auto-generated constructor stub.
ctx = c;
}

@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.tab_1, container, false);

songpath = Environment.getExternalStorageDirectory().getPath() + "/" + getResources().getString(R.string.app_download) + "/music";

// songList = new ArrayList<song>();
// getSongList();

Resources res = getResources();
list = (ListView) v.findViewById(R.id.list);
adapter = new CustomAdaptor1();
arrSongList = new ArrayList<musicdata>();
list.setAdapter(adapter);

seek_bar = (SeekBar) v.findViewById(R.id.songseekbar);

start = (TextView) v.findViewById(R.id.currentduration);
total = (TextView) v.findViewById(R.id.totalduration);

previous = (Button) v.findViewById(R.id.btnpreplay);
next = (Button) v.findViewById(R.id.btnnextplay);
playpause = (Button) v.findViewById(R.id.playpausesong);

previous.setOnClickListener(this);
playpause.setOnClickListener(this);
next.setOnClickListener(this);
seek_bar.setOnSeekBarChangeListener(this);

// Toast.makeText(ctx, songList.size() + "", 100).show();

countaudio();

if(Utils.isInternetConnected(ctx))
{
new load_media_from_url().execute();
}
else
{
alertDialog = new AlertDialog.Builder(ctx).create();
alertDialog.setTitle("! Connection");
alertDialog.setMessage("You Must Have Connected in Internet!!!");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
alertDialog.show();
}
PhoneStateListener phoneStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
}
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
if (mPlayer != null) {
if (!mPlayer.isPlaying()) {
mPlayer.start();
}
}
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
}
}
super.onCallStateChanged(state, incomingNumber);
}
};

TelephonyManager mgr = (TelephonyManager) getActivity()
.getSystemService(Context.TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
return v;
}

public void playknow()
{
// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);
String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
callMediaPlay(list11, true);
playpause.setBackgroundResource(R.drawable.play_pause_press);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}

private void setAudio(int currentsongindex2)
{
// TODO Auto-generated method stub
// songInfo = (Song) songList.get(currentsongindex2);
// Toast.makeText(ctx, songInfo.getAudioPath() + "",
// Toast.LENGTH_LONG).show();
try {
mPlayer.setDataSource(songInfo.getAudioPath());
mPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Runnable run = new Runnable() {
@Override
public void run() {
seekUpdation();
}
};

public void seekUpdation() {
if (mPlayer != null && mPlayer.isPlaying()) {
seek_bar.setProgress(mPlayer.getCurrentPosition());
seekHandler.postDelayed(run, 1000);
start.setText(timetraceed(mPlayer.getCurrentPosition()));
}
}

public String timetraceed(long getduration) {
long minute = ((getduration / 1000) / 60);
long second;

if (mPlayer.getDuration() < 60000) {
second = getduration / 1000;
} else {
second = ((getduration / 1000) % 60);
}
String s = minute + ":" + second;
return s;
}

// --------------------------count for song in music folder----------------------------------------------

public void countaudio() {
sdcard = new ArrayList<string>();
File f = new File(Environment.getExternalStorageDirectory().getPath()
+ "/" + getResources().getString(R.string.app_download)
+ "/music");
File[] dirFiles = f.listFiles();
Toast.makeText(ctx, dirFiles.length+"", 5000).show();
if (dirFiles.length != 0)
{
// loops through the array of files, outputing the name to console
for (int ii = 0; ii < dirFiles.length; ii++)
{
fileOutput = dirFiles[ii].toString();
fileOutput = fileOutput
.substring(fileOutput.lastIndexOf("/") + 1);
sdcard.add(fileOutput.replace(".mp3", ""));
MusicData obj = new MusicData();
obj.name = fileOutput.replace(".mp3", "");
obj.path = f.getAbsolutePath() + "/" + fileOutput;
obj.isDownload = false;

arrSongList.add(obj);
// Toast.makeText(ctx, fileOutput+"", 7000).show();
}

// sdcard = new ArrayList<string>(Arrays.asList(fileOutput));
//Toast.makeText(ctx, sdcard + "", 3000).show();
adapter.addAll(sdcard);
Toast.makeText(ctx, sdcard + "", 3000).show();
list.setAdapter(adapter);
}
}

private void getSongList() {
// TODO Auto-generated method stub
ContentResolver musicResolver = ctx.getContentResolver();
Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = ctx.getContentResolver().query(musicUri, null,
null, null, null);

if (musicCursor != null && musicCursor.moveToFirst()) {
// get columns.....
int titleColumn = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int audiopath = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
// add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisaudiopath = musicCursor.getString(audiopath);
// songList.add(new Song(thisId, thisTitle,
// thisArtist,thisaudiopath));
} while (musicCursor.moveToNext());
}
}

// MediaPlayer mPlayer;

public void play() {
if (mPlayer != null) {
if (mPlayer.isPlaying())
mPlayer.pause();
else
mPlayer.start();
}
}

public void callMediaPlay(String path, boolean resume) {
if (mPlayer != null) {
if (mPlayer.isPlaying())
seekHandler.removeCallbacks(run);
mPlayer.stop();
mPlayer = null;
}

mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

// when song is prepare then the load_media_from_url are call.
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
// TODO Auto-generated method stub
// new load_media_from_url().execute();
}
});

// Toast.makeText(ctx, musicurl+"/"+path, 20000).show();

try {
mPlayer.setDataSource(path);
// Toast.makeText(ctx, musicurl+"/"+path, 2000).show();
mPlayer.prepare();
mPlayer.start();
seek_bar.setMax(mPlayer.getDuration());
seekHandler.postDelayed(run, 1000);
total.setText(timetraceed(mPlayer.getDuration()));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
}
// try {
// mPlayer.prepare();
// } catch (IllegalStateException e) {
// Toast.makeText(ctx, "prepare You might not set the URI correctly!",
// Toast.LENGTH_LONG).show();
// } catch (IOException e) {
// Toast.makeText(ctx, "prepare You might not set the URI correctly!",
// Toast.LENGTH_LONG).show();
// }

}

public void completeplaystop() {
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mPlayer) {
// TODO Auto-generated method stub
mPlayer.stop();
}
});
}

@Override
public void onStop() {
super.onStop();
if (mPlayer != null) {
if (mPlayer.isPlaying())
mPlayer.stop();
mPlayer = null;
}
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub.
if (v == next) {
if (fristplay == false) {
playknow();
fristplay = true;
} else if (currentsongindex < (arrSongList.size() - 1)) {
currentsongindex = currentsongindex + 1;

// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);

String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
callMediaPlay(list11, true);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
} else if (v == previous) {
if (fristplay == false) {
// new load_media_from_url().execute();
playknow();
fristplay = true;
} else if (currentsongindex > 0) {
// new load_media_from_url().execute();
currentsongindex = currentsongindex - 1;

// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);

String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
callMediaPlay(list11, true);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
} else if (v == playpause) {
if (fristplay == false) {
// new load_media_from_url().execute();
playknow();
fristplay = true;
} else if (a == 0 && currentsongindex == 0) {
// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);

String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);

// callMediaPlay(list11, true);

completeplaystop();
playpause.setBackgroundResource(R.drawable.play_pause_press);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
a++;
} else if (a != 0 && mPlayer != null) {
if (mPlayer.isPlaying()) {
// Toast.makeText(ctx, "hello how are you ", 1000).show();
mPlayer.pause();
seekHandler.removeCallbacks(run);
playpause.setBackgroundResource(R.drawable.play_press);
selPosition = -1;
adapter.notifyDataSetChanged();
a = 0;
}
} else if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
seekHandler.removeCallbacks(run);
playpause.setBackgroundResource(R.drawable.play_press);
final Button btnplay = (Button) v
.findViewById(R.id.btnplay);
selPosition = -1;
adapter.notifyDataSetChanged();
} else {
mPlayer.start();
seekHandler.postDelayed(run, 1000);
playpause
.setBackgroundResource(R.drawable.play_pause_press);
final Button btnplay = (Button) v
.findViewById(R.id.btnplay);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
}
}
}

// for tab sliding to this code will be used...

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);

if (this.isVisible())
{
// If we are becoming invisible, then...
if (!isVisibleToUser) {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
posting=true;
}
}
}
else
{
if(posting==true)
{
mPlayer.start();
seekHandler.postDelayed(run, 1000);
}
}
}
}

@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
mPlayer.seekTo(arg1);
arg0.setProgress(arg1);
}

@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}

@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}

// ========================================================custom_adapter=============================================

public class CustomAdaptor1 extends BaseAdapter {
int a = 1;

@Override
public int getCount()
{
// TODO Auto-generated method stub
return arrSongList.size();
}

@Override
public Object getItem(int position)
{
// TODO Auto-generated method stub
return arrSongList.get(position);
}

@Override
public long getItemId(int position)
{
// TODO Auto-generated method stub
return position;
}

@Override
public View getView(final int position, View v, ViewGroup parent)
{
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.custom_row, null);

//Toast.makeText(ctx, ""+arrSongList.get(position), 7000).show();
// songInfo = (Song) songList.get(position);
TextView txtSongName = (TextView) v.findViewById(R.id.txtsongtitle);
final Button btnplay = (Button) v.findViewById(R.id.btnplay);
Button btndownload = (Button) v.findViewById(R.id.btndownload);
Button btnshare = (Button) v.findViewById(R.id.btnshare);

btnplay.setTag(position + "");
txtSongName.setText(arrSongList.get(position).name);

String Url = Environment.getExternalStorageDirectory().getPath()+ "/" + getResources().getString(R.string.app_download)+ "/music";

File f = new File(Url + "/" + arrSongList.get(position));

if (!arrSongList.get(position).isDownload)
{
btndownload.setVisibility(View.GONE);
btndisplay = true;
// arrSongList.set(0,arrSongList.get(position));
// adapter.notifyDataSetChanged();
// notifyDataSetChanged();
}


btnplay.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
if (position == selPosition)
{
if (a == 1)
{
// TODO Auto-generated method stub...
// songInfo = (Song) songList.get(position);
// String path = songInfo.getAudioPath();
// Toast.makeText(ctx, a+"", 2000).show();

String list11 = arrSongList.get(position).path;
callMediaPlay(list11, true);
completeplaystop();
selPosition = position;
// notifyDataSetChanged();
playpause.setBackgroundResource(R.drawable.play_pause_press);
a++;
} else {
// Toast.makeText(ctx, "presssed", 2000).show();
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
selPosition = -1;
// notifyDataSetChanged();
playpause
.setBackgroundResource(R.drawable.play_press);
a = 1;
}
}
}
} else {
// songInfo = (Song) songList.get(position);
// String path = songInfo.getAudioPath();
// Toast.makeText(ctx, a+"", 2000).show();

String list11 = arrSongList.get(position).path;
callMediaPlay(list11, true);
completeplaystop();
selPosition = position;
// notifyDataSetChanged();
playpause
.setBackgroundResource(R.drawable.play_pause_press);
a++;
}
currentsongindex = position;
notifyDataSetChanged();
}
});

if (selPosition == position) {
btnplay.setBackgroundResource(R.drawable.pause_btn);
} else {
btnplay.setBackgroundResource(R.drawable.play_btn);
}

btnshare.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
// songInfo = (Song) songList.get(position);
// String path = songInfo.getAudioPath();

if (!arrSongList.get(position).isDownload)
{
String list11 = "file://"
+ arrSongList.get(position).path;
// Toast.makeText(ctx, list11, 5000).show();
// String mypath = songpath+list11;
sharit(list11);
}
else
{
Toast.makeText(ctx, "required code...", 3000).show();
}
}
});

btndownload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// File wallpaperDirectory = new File("/sdcard/Wallpaper/");
// wallpaperDirectory.mkdirs();

String mypath1 = arrSongList.get(position).name;
Toast.makeText(ctx, mypath1 + "", 5000).show();

downloadMusic(mypath1, position);

// Toast.makeText(ctx,arrSongList.get(position) +"",
// 2000).show();
// File outputFile = new File(wallpaperDirectory, filename);
// FileOutputStream fos = new FileOutputStream(outputFile);
}
});
return v;
}

private void sharit(String path)
{
Uri uri = Uri.parse(path);
Intent sharingintent = new Intent(
android.content.Intent.ACTION_SEND);
sharingintent.setType("audio/*");
sharingintent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingintent,"SHARE AUDIO FILE"));

if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
}
}

public void addAll(ArrayList<string> arrList)
{
// TODO Auto-generated method stub
}
}

@Override
public void onPause()
{
// TODO Auto-generated method stub
super.onPause();
activitystate = "pause";
selPosition = -1;
if (adapter != null)
adapter.notifyDataSetChanged();
playpause.setBackgroundResource(R.drawable.play_press);
}

@Override
public void onResume()
{
// TODO Auto-generated method stub
super.onResume();
if (activitystate.equals("pause"))
{
if (mPlayer != null)
{
mPlayer.start();
seekHandler.postDelayed(run, 0000);
// Toast.makeText(ctx, "pause", 2000).show();
selPosition = currentsongindex;
if (adapter != null)
adapter.notifyDataSetChanged();
playpause.setBackgroundResource(R.drawable.play_pause_press);
}
}
}

@Override
public void onDestroy()
{
super.onDestroy();
try
{
seekHandler.removeCallbacks(run);
}
catch (Exception e)
{
}
}

// ===========================================class for getsonglist============================================

class getSongList extends AsyncTask<void, void,="" boolean="">
{
@Override
protected Boolean doInBackground(Void... params)
{
// ArrayList<string> mStringsmyurls = new ArrayList<string>();
String SOAP_ACTIONname = "ns_songlist/get_song_name_list";
String METHOD_NAMEname = "get_song_name_list";
SoapObject result = null;

String NAMESPACE = "ns_songlist";
String URL = "http://exporterp.in/vm/ws_songlist.asmx";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAMEname);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {
androidHttpTransport.call(SOAP_ACTIONname, envelope);
} catch (SocketTimeoutException e) {
return false;
} catch (IOException e) {
return false;
} catch (XmlPullParserException e) {
return false;
}

try {
result = (SoapObject) envelope.getResponse();
if (result != null) {
for (int i = 0; i < result.getPropertyCount(); i++) {
String musicname = ""
+ result.getProperty(i).toString();
if (!sdcard.contains(musicname))
{
MusicData obj = new MusicData();
obj.name = musicname.replace(".mp3", "");
obj.path = "http://exporterp.in/vm/songs/"
+ musicname.replace(".mp3", "") + ".mp3";
obj.isDownload = true;
arrSongList.add(obj);
}
}
return true;
} else
return false;
} catch (SoapFault e) {
return false;
} catch (Exception e) {
return false;
}
}

// @Override
// protected void onProgressUpdate(Void... values) {
// super.onProgressUpdate(values);
// }
}

// ===============================class for show dialogebox======================================================

class load_media_from_url extends AsyncTask<void, void,="" boolean="">
{
ProgressDialog pd = null;

@Override
protected void onPreExecute() {
pd = new ProgressDialog(ctx);
pd.setMessage("Loading...");
pd.setCancelable(false);
pd.show();
}

@Override
protected Boolean doInBackground(Void... params) {
return new getSongList().doInBackground();
}

@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (pd != null && pd.isShowing())
pd.dismiss();

// freeAudioAdapter.addAll(arrList);
// adapter.addAll(arrSongList);

adapter = new CustomAdaptor1();
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
if (!result)
Toast.makeText(ctx, "Error in Downloading File...",Toast.LENGTH_SHORT).show();
// else
// Toast.makeText(ctx, arrSongList + "", 2000).show();
}
}

public void downloadMusic(String mname, int position)
{
if (Utils.isInternetConnected(ctx)) {
new downloadMusicTask(mname, position).execute();
} else {
Toast.makeText(ctx,
"Please Connect to Internet For Load More Music...",
Toast.LENGTH_SHORT).show();
}
}

class downloadMusicTask extends AsyncTask<void, integer,="" boolean=""> {
String musicname = "";
int position = 0;
ProgressDialog mProgressDialog = null;

public downloadMusicTask(String mname, int pos) {
musicname = mname;
position = pos;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(ctx);
mProgressDialog.setMessage("Downloading Music..");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}

@Override
protected Boolean doInBackground(Void... params)
{
String uri = musicurl + musicname + ".mp3";

File f = new File(Environment.getExternalStorageDirectory()
.getPath()
+ "/"
+ getResources().getString(R.string.app_download));

if (!f.exists()) {
f.mkdir();
}

f = new File(Environment.getExternalStorageDirectory().getPath()
+ "/" + getResources().getString(R.string.app_download)
+ "/music");

if (!f.exists()) {
f.mkdir();
}

if (folderPath == null || folderPath.equals("")) {
folderPath = Environment.getExternalStorageDirectory()
.getPath()
+ "/"
+ getResources().getString(R.string.app_download);
}

StorePath = folderPath + "/music/" + musicname + ".mp3";
// Toast.makeText(ctx, StorePath+"storepath diaply",7000).show();

try
{
URL url = new URL(uri);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(StorePath);

byte data[] = new byte[1024];
int count;
long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
publishProgress((int) ((total * 100) / lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
catch (Exception e)
{
return false;
}
return true;
}

@Override
protected void onProgressUpdate(Integer... values)
{
if (mProgressDialog != null)
mProgressDialog.setProgress(values[0]);
}

@Override
protected void onPostExecute(Boolean result)
{
super.onPostExecute(result);
if (mProgressDialog != null && mProgressDialog.isShowing())
mProgressDialog.dismiss();
if (result)
{
arrSongList.get(position).isDownload = false;

File f=new File(StorePath);
if(f.exists())
{
//f.delete();
MediaScannerConnection.scanFile(ctx, new String[] { f.getAbsolutePath() },new String[] { "audio/*" },null);
}

// arrSongList.clear();
// countaudio() ;
adapter.notifyDataSetChanged();
// countaudio() ;
}
else
{
Toast.makeText(ctx, "File Download Error", Toast.LENGTH_SHORT).show();
}
}
}

// private void getMediaFileName()
// {
// if (folderPath == null || folderPath.equals(""))
// {
// folderPath = Environment.getExternalStorageDirectory().getPath()
// + "/" + getResources().getString(R.string.app_download);
// }
// String StorePath = folderPath + "/music";
// File mfile = new File(StorePath);
//
// arrSongList = new ArrayList<musicdata>();
//
// if (mfile.exists())
// {
// String[] files = mfile.list();
// if (files.length > 0)
// for (String file : files)
// {
// File f = new File(file);
// String musicname = "" + f.getName();
// // arrSongList.add(musicname);
//
// if (!arrSongList.contains(musicname))
// {
// // arrSongList.add(musicname);
// }
// }
// }
// }
}
AnswerRe: android listview display data in sdcard to top position in my listciew. Pin
Richard MacCutchan9-Jul-15 22:08
mveRichard MacCutchan9-Jul-15 22:08 
QuestionPanorama viewer with gyro support - Html5 Pin
martin prochazka 19799-Jul-15 11:50
martin prochazka 19799-Jul-15 11:50 
AnswerRe: Panorama viewer with gyro support - Html5 Pin
Richard MacCutchan9-Jul-15 22:05
mveRichard MacCutchan9-Jul-15 22:05 
GeneralRe: Panorama viewer with gyro support - Html5 Pin
martin prochazka 197912-Jul-15 3:42
martin prochazka 197912-Jul-15 3:42 
QuestionUploading Video to server through SOAP webservice using Android Pin
Member 116050787-Jul-15 0:02
Member 116050787-Jul-15 0:02 
AnswerRe: Uploading Video to server through SOAP webservice using Android Pin
Richard MacCutchan7-Jul-15 1:58
mveRichard MacCutchan7-Jul-15 1:58 
QuestionHow to implement unlimited number of text views Pin
jasonalien6-Jul-15 21:46
jasonalien6-Jul-15 21:46 
AnswerRe: How to implement unlimited number of text views Pin
Richard MacCutchan6-Jul-15 22:05
mveRichard MacCutchan6-Jul-15 22:05 
QuestionWebsocket timeout via NGINX only in a 3G hotspot Pin
Dickens A S2-Jul-15 16:53
professionalDickens A S2-Jul-15 16:53 
QuestionGalery camera android Pin
Ibrahim.elh2-Jul-15 2:42
Ibrahim.elh2-Jul-15 2:42 
SuggestionRe: Galery camera android Pin
David Crow2-Jul-15 4:55
David Crow2-Jul-15 4:55 
Questionthe find registered source SIM Tool Kit ? Pin
Member 245846720-Jun-15 13:28
Member 245846720-Jun-15 13:28 
AnswerRe: the find registered source SIM Tool Kit ? Pin
Richard MacCutchan20-Jun-15 21:20
mveRichard MacCutchan20-Jun-15 21:20 
GeneralRe: the find registered source SIM Tool Kit ? Pin
Member 245846721-Jun-15 3:20
Member 245846721-Jun-15 3:20 
Question"Search your Doctor " Pin
Member 1084090620-Jun-15 10:54
Member 1084090620-Jun-15 10:54 
QuestionRe: "Search your Doctor " Pin
David Crow20-Jun-15 17:02
David Crow20-Jun-15 17:02 
QuestionHow can I record local media stream. Pin
Member 1161266218-Jun-15 22:00
Member 1161266218-Jun-15 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.