7
我正在流式無線電流。我想在流中的歌曲改變時生成通知。我使用streamscraper(http://code.google.com/p/streamscraper)獲取當前流的元數據,並嘗試在元數據更改時生成通知。調用異步任務
以下是我爲實現此目的而創建的異步任務。
public class updateMetadata extends
AsyncTask<String, Void, PlaylistSong<BaseArtist, BaseAlbum>> {
private static final String TAG = updateMetadata.class.getSimpleName();
private PlaylistSong<BaseArtist, BaseAlbum> oldSong = null;
private PlaylistSong<BaseArtist, BaseAlbum> newSong = null;
private metadataHarvester fetchMetadata = new metadataHarvester();
private String streamUrl = null;
@Override
protected PlaylistSong<BaseArtist, BaseAlbum> doInBackground(String... urls) {
for (String url : urls) {
try {
oldSong = fetchMetadata.prepareRadioSong(url);
} catch (Exception e) {
e.printStackTrace();
}
streamUrl = url;
}
newSong = oldSong;
while (newSong == oldSong) {
try {
newSong = fetchMetadata.prepareRadioSong(streamUrl);
} catch (Exception e) {
e.printStackTrace();
}
}
return newSong;
}
@Override
protected void onPostExecute(PlaylistSong<BaseArtist, BaseAlbum> song) {
Log.v(TAG, "New Song: " + song.getTitle());
}
}
該應用程序構建在兩個鏈接的項目上。項目A是應用程序初始化的位置,項目B包含收集和播放邏輯。我想在Project B中使用這個任務。這裏是播放功能(在項目B中)。
protected synchronized void play(final IMediaPlayerWrapper mp) {
streamURL = streamFetcher.getStreamUrl();
Log.i(TAG, "Stream URL: " + streamURL);
try {
Log.i(TAG, "Testing metadata harvester");
radioSong = metadata.prepareRadioSong(streamURL);
} catch (Exception e) {
Log.w(TAG, e);
}
updateMetadata(radioSong);
currentPlaylistManager.clearPlaylist();
currentPlaylistManager.appendSongAtEnd(radioSong);
listenerInformer.informCurrentSongChangeListener(radioSong);
try {
mp.setSong(radioSong, streamURL);
mp.play();
if (mp.isPlaying()) {
setPlayerState(PlayerState.PLAY);
}
} catch (Exception e) {
Log.w(TAG, e);
setPlayerState(PlayerState.ERROR);
}
updateMetadata metadataChecker = new updateMetadata();
metadataChecker.execute(streamURL);
}
當我試着執行它時,應用程序崩潰。
這裏,是完全錯誤跟蹤:
04-04 23:34:34.975: E/WindowManager(18080): Activity ch.ethz.dcg.pancho2.view.radioplayer.RadioPlayerActivity has leaked window [email protected] that was originally added here
04-04 23:34:34.975: E/WindowManager(18080): android.view.WindowLeaked: Activity ch.ethz.dcg.pancho2.view.radioplayer.RadioPlayerActivity has leaked window [email protected] that was originally added here
04-04 23:34:34.975: E/WindowManager(18080): at android.view.ViewRoot.<init>(ViewRoot.java:258)
04-04 23:34:34.975: E/WindowManager(18080): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
04-04 23:34:34.975: E/WindowManager(18080): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-04 23:34:34.975: E/WindowManager(18080): at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-04 23:34:34.975: E/WindowManager(18080): at android.app.Dialog.show(Dialog.java:241)
04-04 23:34:34.975: E/WindowManager(18080): at android.app.ProgressDialog.show(ProgressDialog.java:107)
04-04 23:34:34.975: E/WindowManager(18080): at android.app.ProgressDialog.show(ProgressDialog.java:90)
04-04 23:34:34.975: E/WindowManager(18080): at ch.ethz.dcg.pancho2.view.radioplayer.RadioPlayerActivity$5.onClick(RadioPlayerActivity.java:276)
04-04 23:34:34.975: E/WindowManager(18080): at android.view.View.performClick(View.java:2485)
04-04 23:34:34.975: E/WindowManager(18080): at android.view.View$PerformClick.run(View.java:9080)
04-04 23:34:34.975: E/WindowManager(18080): at android.os.Handler.handleCallback(Handler.java:587)
04-04 23:34:34.975: E/WindowManager(18080): at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 23:34:34.975: E/WindowManager(18080): at android.os.Looper.loop(Looper.java:130)
04-04 23:34:34.975: E/WindowManager(18080): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-04 23:34:34.975: E/WindowManager(18080): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 23:34:34.975: E/WindowManager(18080): at java.lang.reflect.Method.invoke(Method.java:507)
04-04 23:34:34.975: E/WindowManager(18080): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-04 23:34:34.975: E/WindowManager(18080): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-04 23:34:34.975: E/WindowManager(18080): at dalvik.system.NativeStart.main(Native Method)
在我的異步任務的理解,我很困惑。這不是使用它們的正確方法嗎?
編輯:單獨答覆。
基本上,您正試圖在退出活動後顯示對話框。發生上述情況有各種原因,但在代碼中沒有看到有關對話的任何信息。你使用對話框嗎? – 2012-04-04 21:59:13
不,我正在嘗試在當前歌曲發生變化後記錄新歌曲。在這個階段沒有對話或任何東西。我已經設置了onSongChanged監聽器。我可以打電話,當我確定檢查新歌曲位正在工作。 – rahulthewall 2012-04-04 22:38:54
您是否試圖在RadioPlayerActivity onclick方法中顯示任何對話框或進度對話框? – Ads 2012-06-13 10:02:42