我有三个活动链接意图(活动A意图 - >活动B(intentA + intentB) - >活动C)我在Manifest中使用父活动....当按回导航或呼叫按钮取消时出现问题beget error NullPointerException:Activity B(intentA + intentB)。但我按下设备没问题。
请帮助我!
抱歉!我说英语非常糟糕:(
代码活动A
package com.example.musicquality;
import java.util.ArrayList;
import java.util.Vector;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.example.Play.SongAdapter;
import com.example.Utils.NetworkUtils;
import com.example.Utils.Utils;
public class SongActivity extends Activity {
public ArrayList<String> mSong = new ArrayList<String>();
public ArrayList<String> linkSong = new ArrayList<String>();
private ArrayList<String> linkImage = new ArrayList<String>();
final String user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) "
+ " AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
public String changeLink;
private String linkIntent;
final String selectLinkPlay = "div#downloadlink a";
final String afterChangeLink = "";
private String select = ".txtsp1";
private String url = "http://chiasenhac.com/mp3/vietnam";
public ProgressDialog pDialog;
private ListView lvSong;
private String nameSong;
@SuppressWarnings("unused")
private ImageView image;
private int positionId;
private Intent intentData;
private ImageButton btnSearch;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.song_layout);
if (NetworkUtils.isNetworkAvailable(this)) {
new loadDataGet().execute();
} else {
Toast.makeText(SongActivity.this, "Please check internet access !",
Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onBackPressed() {
if (!NetworkUtils.isNetworkAvailable(this)) {
finish();
}
super.onBackPressed();
}
public class loadDataGet extends
AsyncTask<String, Void, Vector<ArrayList<String>>> {
@Override
protected void onPostExecute(Vector<ArrayList<String>> result) {
pDialog.dismiss();
lvSong = (ListView) findViewById(R.id.lvSong);
image = (ImageView) findViewById(R.id.ivIconSong);
TextView tvTitle = (TextView) findViewById(R.id.tvSong);
tvTitle.setSelected(true);
btnSearch = (ImageButton) findViewById(R.id.ibtnseachbox);
btnSearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
SongAdapter adapter = new SongAdapter(SongActivity.this,
R.layout.listsong_layout, R.id.tvNameSong, R.id.ivIconSong,
mSong, linkImage);
lvSong.setAdapter(adapter);
lvSong.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
view.setSelected(true);
positionId = position;
nameSong = (String) lvSong.getItemAtPosition(positionId);
linkIntent = linkSong.get(position);
intentData = new Intent(getBaseContext(),
PlayMusicActivity.class);
intentData.putExtra("namesong", nameSong);
intentData.putExtra("data", linkIntent);
startActivity(intentData);
}
});
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
pDialog = ProgressDialog.show(SongActivity.this, "", "Loading...");
}
@Override
protected Vector<ArrayList<String>> doInBackground(String... params) {
Vector<ArrayList<String>> data = new Vector<ArrayList<String>>();
try {
String urlImage = "http://chiasenhac.com/mp3/vietnam/";
mSong = (ArrayList<String>) Utils.getInfo(data, select,
linkSong, mSong, url).get(0);
linkSong = (ArrayList<String>) Utils.getInfo(data, select,
linkSong, mSong, url).get(1);
linkImage = (ArrayList<String>) Utils.getLinkImages(urlImage,
linkImage);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Server has problem... Please while for minutes",
Toast.LENGTH_SHORT).show();
}
return data;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_action, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share:
return true;
case R.id.action_setting:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
代码活动B(intentA + intentB)和活动C
活动B(intentA + intentB)。我使用Asynctask。点击下载按钮
启动活动C.public class startNewActivity extends AsyncTask<String, Void, String> {
private String selectDoc = "div.gen img";
private String attr = "title";
private String resultOfLyric;
private String result = "";
public String Quality;
private String getQuality;
private String checkQuality;
private String checkSupportDownload;
@Override
protected String doInBackground(String... arg0) {
try {
lyric = Utils.testGetLyric(link, useReplace, resultOfLyric);
getQuality = Utils.getQuality(link, selectDoc, attr, result);
Quality = getQuality.substring(0, 5);
checkQuality = getQuality.substring(5).replace(" ", "");
changeLink = link.replace(".html", "_download.html").substring(15)
.replaceFirst("", "http://download")
.replace("nhac-hot", "mp3".concat("/vietnam/v-pop"));
dataGetPlayAndDown = Utils.getLinkPlay(selectLinkPlay,
changeLink, dataGetPlayAndDown);
urlDataSource = dataGetPlayAndDown.get(0);
linkDownload = dataGetPlayAndDown.get(1);
checkSupportDownload = Utils.checkSupportDownload(changeLink,
result);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Server has problem... Please while for minutes",
Toast.LENGTH_SHORT).show();
}
return urlDataSource;
}
@Override
protected void onPostExecute(String result) {
pDialog.dismiss();
playSong(urlDataSource);
tvLink = (TextView) findViewById(R.id.tvLink);
edTLyric = (EditText) findViewById(R.id.edTLyric);
tvTotalTime = (TextView) findViewById(R.id.timeofSong);
tvCurrentTime = (TextView) findViewById(R.id.timeIsPlay);
btnDownload = (ImageButton) findViewById(R.id.imgbtDownload);
rad32kb = (RadioButton) findViewById(R.id.rad32Kb);
rad128kb = (RadioButton) findViewById(R.id.rad128Kb);
rad320kb = (RadioButton) findViewById(R.id.rad320Kb);
rad500kb = (RadioButton) findViewById(R.id.rad500);
if (Quality.equals("32kb ")) {
rad32kb.setChecked(true);
}
if (Quality.equals("128kb")) {
rad128kb.setChecked(true);
}
if (Quality.equals("320kb")) {
rad320kb.setChecked(true);
}
if (Quality.equals("500kb")) {
rad500kb.setChecked(true);
}
if (checkQuality.equals("3")) {
rad500kb.setEnabled(false);
} else if (checkQuality.equals("3-256k")) {
rad500kb.setEnabled(false);
} else if (checkQuality.equals("2")) {
rad500kb.setEnabled(false);
rad320kb.setEnabled(false);
}
tvLink.setText(nameSong);
edTLyric.setText(lyric);
btnDownload.setOnClickListener(new OnClickListener() {
**// Intent Here**
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),
DownloadActivity.class);
intent.putExtra("download", linkDownload);
intent.putExtra("fileName", nameSong);
intent.putExtra("checkSupport", checkSupportDownload);
startActivity(intent);
}
});
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
pDialog = ProgressDialog.show(PlayMusicActivity.this, "",
"Please wait...");
intent = getIntent();
link = intent.getStringExtra("data");
**// I think nameSong nullpointer**
nameSong = intent.getStringExtra("namesong");
**//When press back Navigation. Log cat give error null pointer here**
useReplace = nameSong.substring(0, nameSong.indexOf("-"));
}
}
活动C(下载活动)
代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.download_layout);
PACKAGE_NAME = getApplicationContext().getPackageName();
imgDownload = (ImageButton) findViewById(R.id.btnDownload);
imgCancel = (ImageButton) findViewById(R.id.btnCancel);
radDown128kb = (RadioButton) findViewById(R.id.radDownload128Kb);
radDown320kb = (RadioButton) findViewById(R.id.radDownload320Kb);
radDown500kb = (RadioButton) findViewById(R.id.radDownload500);
radDownLoss = (RadioButton) findViewById(R.id.radDownloadFlac);
tvSupport = (TextView) findViewById(R.id.tvSupportSize);
Intent intent = getIntent();
linkdownload = intent.getStringExtra("download");
titleName = intent.getStringExtra("fileName");
fileName = titleName.concat(".mp3");}
按钮取消。
imgCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent backActi = new Intent(getBaseContext(),
PlayMusicActivity.class);
startActivity(backActi);
DownloadActivity.this.finish();
}
});
}
Android Manifest
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.musicquality.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Song Activity -->
<activity android:name="com.example.musicquality.SongActivity" />
<!-- List Activity -->
<activity android:name="com.example.musicquality.PlaylistActivity" />
<!-- Singer Activity -->
<activity android:name="com.example.musicquality.SingerActivity" />
<!-- PlayMusic Activity -->
<activity
android:name="com.example.musicquality.PlayMusicActivity"
android:parentActivityName="com.example.musicquality.SongActivity" />
<!-- Download Activity -->
<activity android:name="com.example.musicquality.DownloadActivity"
android:parentActivityName="com.example.musicquality.PlayMusicActivity"/>
<!-- Search Activity -->
<activity
android:name="com.example.musicquality.SearchActivity"
android:parentActivityName="com.example.musicquality.SongActivity" >
</activity>
</application>
logcat的
07-23 02:44:30.136: E/AndroidRuntime(1654): FATAL EXCEPTION: main
07-23 02:44:30.136: E/AndroidRuntime(1654): Process: com.example.musicquality, PID: 1654
07-23 02:44:30.136: E/AndroidRuntime(1654): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.musicquality/com.example.musicquality.PlayMusicActivity}: java.lang.NullPointerException
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.os.Handler.dispatchMessage(Handler.java:102)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.os.Looper.loop(Looper.java:136)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-23 02:44:30.136: E/AndroidRuntime(1654): at java.lang.reflect.Method.invokeNative(Native Method)
07-23 02:44:30.136: E/AndroidRuntime(1654): at java.lang.reflect.Method.invoke(Method.java:515)
07-23 02:44:30.136: E/AndroidRuntime(1654): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-23 02:44:30.136: E/AndroidRuntime(1654): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-23 02:44:30.136: E/AndroidRuntime(1654): at dalvik.system.NativeStart.main(Native Method)
07-23 02:44:30.136: E/AndroidRuntime(1654): Caused by: java.lang.NullPointerException
07-23 02:44:30.136: E/AndroidRuntime(1654): at com.example.musicquality.PlayMusicActivity$startNewActivity.onPreExecute(PlayMusicActivity.java:272)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.os.AsyncTask.execute(AsyncTask.java:535)
07-23 02:44:30.136: E/AndroidRuntime(1654): at com.example.musicquality.PlayMusicActivity.onCreate(PlayMusicActivity.java:68)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.Activity.performCreate(Activity.java:5231)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-23 02:44:30.136: E/AndroidRuntime(1654): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
07-23 02:44:30.136: E/AndroidRuntime(1654): ... 11 more
我是新手Android。我的代码不好:(。请!尽快回复
编辑
package com.example.musicquality;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import com.example.Utils.Utils;
public class PlayMusicActivity extends Activity implements OnClickListener,
OnTouchListener, OnCompletionListener, OnBufferingUpdateListener,
OnCheckedChangeListener, OnPreparedListener {
private MediaPlayer mPlay;
private int LenghData;
private SeekBar seekBar;
private ImageButton btnPlay;
private String link;
private String nameSong;
private TextView tvLink;
private TextView tvTotalTime;
private TextView tvCurrentTime;
private RadioButton rad32kb;
private RadioButton rad128kb;
private RadioButton rad320kb;
private RadioButton rad500kb;
private ImageButton btnDownload;
private String changeLink;
private String useReplace;
private ProgressDialog pDialog;
final String selectLinkPlay = "div#downloadlink a";
private String urlDataSource;
private RadioGroup group;
private String ifChangeCheck;
private String lyric;
private final Handler handler = new Handler();
private EditText edTLyric;
private ArrayList<String> dataGetPlayAndDown;
private String linkDownload;
private Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playmusic_layout);
new startNewActivity().execute();
group = (RadioGroup) findViewById(R.id.radioGroup);
group.setOnCheckedChangeListener(this);
}
private void playSong(String urlData) {
btnPlay = (ImageButton) findViewById(R.id.btnPlay);
seekBar = (SeekBar) findViewById(R.id.seekBar);
btnPlay.setOnClickListener(this);
seekBar.setMax(99);
seekBar.setOnTouchListener(this);
mPlay = new MediaPlayer();
mPlay.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlay.setOnBufferingUpdateListener(this);
mPlay.setOnCompletionListener(this);
try {
mPlay.setDataSource(urlData);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// Error when Seekbar don't set value or value = 0
private void primaryUpdateSeekBar() {
seekBar.setProgress((int) (((float) mPlay.getCurrentPosition() / LenghData) * 100));
if (mPlay.isPlaying()) {
Runnable notification = new Runnable() {
@Override
public void run() {
long totalDuration = mPlay.getDuration();
long currentDuration = mPlay.getCurrentPosition();
tvTotalTime.setText(Utils.getTimeString(totalDuration));
tvCurrentTime.setText(Utils.getTimeString(currentDuration));
primaryUpdateSeekBar();
}
};
handler.postDelayed(notification, 1000);
}
}
@Override
public void onBackPressed() {
if (mPlay.isPlaying()) {
mPlay.stop();
}
super.onBackPressed();
}
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
seekBar.setSecondaryProgress(percent);
}
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
btnPlay.setImageResource(R.drawable.play);
seekBar.setProgress(0);
seekBar.setSecondaryProgress(0);
tvTotalTime.setText("00:00");
tvCurrentTime.setText("");
try {
playSong(ifChangeCheck);
mPlay.prepareAsync();
mPlay.setOnPreparedListener(this);
mPlay.setLooping(true);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
@Override
public boolean onTouch(View view, MotionEvent event) {
if (view.getId() == R.id.seekBar) {
SeekBar seekbar = (SeekBar) view;
int playPositioninMiliseconds = (LenghData / 100)
* seekbar.getProgress();
mPlay.seekTo(playPositioninMiliseconds);
}
return false;
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.btnPlay) {
try {
mPlay.prepare();
} catch (Exception e) {
e.printStackTrace();
}
LenghData = mPlay.getDuration();
if (!mPlay.isPlaying()) {
mPlay.start();
btnPlay.setImageResource(R.drawable.pause_icon);
} else {
mPlay.pause();
btnPlay.setImageResource(R.drawable.play);
}
primaryUpdateSeekBar();
}
}
public class startNewActivity extends AsyncTask<String, Void, String> {
private String selectDoc = "div.gen img";
private String attr = "title";
private String resultOfLyric;
private String result = "";
public String Quality;
private String getQuality;
private String checkQuality;
private String checkSupportDownload;
@Override
protected String doInBackground(String... arg0) {
try {
lyric = Utils.testGetLyric(link, useReplace, resultOfLyric);
getQuality = Utils.getQuality(link, selectDoc, attr, result);
Quality = getQuality.substring(0, 5);
checkQuality = getQuality.substring(5).replace(" ", "");
changeLink = link.replace(".html", "_download.html")
.substring(15).replaceFirst("", "http://download")
.replace("nhac-hot", "mp3".concat("/vietnam/v-pop"));
dataGetPlayAndDown = Utils.getLinkPlay(selectLinkPlay,
changeLink, dataGetPlayAndDown);
urlDataSource = dataGetPlayAndDown.get(0);
linkDownload = dataGetPlayAndDown.get(1);
checkSupportDownload = Utils.checkSupportDownload(changeLink,
result);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Server has problem... Please while for minutes",
Toast.LENGTH_SHORT).show();
}
return urlDataSource;
}
@Override
protected void onPostExecute(String result) {
pDialog.dismiss();
playSong(urlDataSource);
tvLink = (TextView) findViewById(R.id.tvLink);
edTLyric = (EditText) findViewById(R.id.edTLyric);
tvTotalTime = (TextView) findViewById(R.id.timeofSong);
tvCurrentTime = (TextView) findViewById(R.id.timeIsPlay);
btnDownload = (ImageButton) findViewById(R.id.imgbtDownload);
rad32kb = (RadioButton) findViewById(R.id.rad32Kb);
rad128kb = (RadioButton) findViewById(R.id.rad128Kb);
rad320kb = (RadioButton) findViewById(R.id.rad320Kb);
rad500kb = (RadioButton) findViewById(R.id.rad500);
if (Quality.equals("32kb ")) {
rad32kb.setChecked(true);
}
if (Quality.equals("128kb")) {
rad128kb.setChecked(true);
}
if (Quality.equals("320kb")) {
rad320kb.setChecked(true);
}
if (Quality.equals("500kb")) {
rad500kb.setChecked(true);
}
if (checkQuality.equals("3")) {
rad500kb.setEnabled(false);
} else if (checkQuality.equals("3-256k")) {
rad500kb.setEnabled(false);
} else if (checkQuality.equals("2")) {
rad500kb.setEnabled(false);
rad320kb.setEnabled(false);
}
tvLink.setText(nameSong);
edTLyric.setText(lyric);
btnDownload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(),
DownloadActivity.class);
intent.putExtra("download", linkDownload);
intent.putExtra("fileName", nameSong);
intent.putExtra("checkSupport", checkSupportDownload);
startActivity(intent);
PlayMusicActivity.this.finish();
}
});
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
pDialog = ProgressDialog.show(PlayMusicActivity.this, "",
"Please wait...");
intent = getIntent();
link = intent.getStringExtra("data");
nameSong = intent.getStringExtra("namesong");
useReplace = nameSong.substring(0, nameSong.indexOf("-"));
}
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (group.getCheckedRadioButtonId()) {
case R.id.rad32Kb:
String aftercheck32 = "";
int checkLinkIsPlay32 = urlDataSource.lastIndexOf("/") - 3;
String subString32 = urlDataSource.substring(checkLinkIsPlay32);
if (subString32.contains("128")) {
aftercheck32 = urlDataSource.replace("/128/", "/32/").replace(
".mp3", ".m4a");
} else if (subString32.contains("320")) {
aftercheck32 = urlDataSource.replace("/320/", "/32/").replace(
".mp3", ".m4a");
} else if (subString32.contains("m4a")) {
aftercheck32 = urlDataSource.replace("/m4a/", "/32/");
}
ifChangeCheck = aftercheck32;
try {
if (mPlay != null) {
mPlay.stop();
mPlay.reset();
}
playSong(ifChangeCheck);
mPlay.setLooping(true);
} catch (IllegalStateException e) {
e.printStackTrace();
}
break;
case R.id.rad128Kb:
try {
if (mPlay != null) {
ifChangeCheck = urlDataSource;
mPlay.stop();
mPlay.reset();
}
playSong(urlDataSource);
mPlay.setLooping(true);
} catch (IllegalStateException e) {
e.printStackTrace();
}
break;
case R.id.rad320Kb:
String aftercheck320 = "";
int checkLinkIsPlay320 = urlDataSource.lastIndexOf("/") - 3;
String subLink320 = urlDataSource.substring(checkLinkIsPlay320);
if (subLink320.contains("/32")) {
aftercheck320 = urlDataSource.replace("/32/", "/320/").replace(
".m4a", ".mp3");
} else if (subLink320.contains("128")) {
aftercheck320 = urlDataSource.replace("/128/", "/320/");
} else if (subLink320.contains("m4a")) {
aftercheck320 = urlDataSource.replace("/m4a/", "/320/")
.replace(".m4a", ".mp3");
}
ifChangeCheck = aftercheck320;
try {
if (mPlay != null) {
mPlay.stop();
mPlay.reset();
}
playSong(ifChangeCheck);
mPlay.setLooping(true);
} catch (IllegalStateException e) {
e.printStackTrace();
}
break;
case R.id.rad500:
String aftercheck500 = "";
int checkLinkIsPlay500 = urlDataSource.lastIndexOf("/") - 3;
String subLink500 = urlDataSource.substring(checkLinkIsPlay500);
if (subLink500.contains("/32")) {
aftercheck500 = urlDataSource.replace("/32/", "/m4a/");
} else if (subLink500.contains("128")) {
aftercheck500 = urlDataSource.replace("/128/", "/m4a/")
.replace(".mp3", ".m4a");
} else if (subLink500.contains("320")) {
aftercheck500 = urlDataSource.replace("/320/", "/m4a/")
.replace(".mp3", ".m4a");
}
ifChangeCheck = aftercheck500;
try {
if (mPlay != null) {
mPlay.stop();
mPlay.reset();
}
playSong(ifChangeCheck);
mPlay.setLooping(true);
} catch (IllegalStateException e) {
e.printStackTrace();
}
break;
default:
break;
}
}
@Override
public void onPrepared(MediaPlayer mp) {
if (mPlay != null) {
mPlay.start();
btnPlay.setImageResource(R.drawable.pause_icon);
} else {
mPlay.pause();
btnPlay.setImageResource(R.drawable.play);
}
mPlay.start();
primaryUpdateSeekBar();
}
}
答案 0 :(得分:1)
我明白了:
link = intent.getStringExtra("data");
nameSong = intent.getStringExtra("namesong");
但我无法找到:
intent.putExtra("data", "...");
intent.putExtra("namesong", "...");
编辑imgCancel.setOnClickListener:
imgCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent backActi = new Intent(getBaseContext(),
PlayMusicActivity.class);
backActi.putExtra("data", linkdownload);
backActi.putExtra("namesong", titleName);
startActivity(backActi);
DownloadActivity.this.finish();
}
});
}