1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
|
/*
This file is part of Subsonic.
Subsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009 (C) Sindre Mehus
*/
package github.daneren2005.dsub.fragments;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragment;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.DownloadActivity;
import github.daneren2005.dsub.activity.HelpActivity;
import github.daneren2005.dsub.activity.MainActivity;
import github.daneren2005.dsub.activity.SearchActivity;
import github.daneren2005.dsub.activity.SettingsActivity;
import github.daneren2005.dsub.activity.SubsonicActivity;
import github.daneren2005.dsub.domain.Artist;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.DownloadServiceImpl;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.service.OfflineException;
import github.daneren2005.dsub.service.ServerTooOldException;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.ModalBackgroundTask;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.Util;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class SubsonicFragment extends SherlockFragment {
private static final String TAG = SubsonicFragment.class.getSimpleName();
protected SubsonicActivity context;
protected CharSequence title = "DSub";
protected View rootView;
protected boolean primaryFragment = false;
protected boolean invalidated = false;
protected static Random random = new Random();
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
context = (SubsonicActivity)activity;
}
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_refresh:
refresh(true);
return true;
case R.id.menu_shuffle:
onShuffleRequested();
return true;
case R.id.menu_search:
context.onSearchRequested();
return true;
case R.id.menu_exit:
exit();
return true;
case R.id.menu_settings:
startActivity(new Intent(context, SettingsActivity.class));
return true;
case R.id.menu_help:
startActivity(new Intent(context, HelpActivity.class));
return true;
}
return false;
}
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo, Object selected) {
MenuInflater inflater = context.getMenuInflater();
if(selected instanceof MusicDirectory.Entry) {
MusicDirectory.Entry entry = (MusicDirectory.Entry) selected;
if (entry.isDirectory()) {
if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_album_context_offline, menu);
}
else {
inflater.inflate(R.menu.select_album_context, menu);
}
} else if(!entry.isVideo()) {
if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_song_context_offline, menu);
}
else {
inflater.inflate(R.menu.select_song_context, menu);
}
} else {
if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_video_context_offline, menu);
}
else {
inflater.inflate(R.menu.select_video_context, menu);
}
}
if (!Util.isOffline(context) && !entry.isVideo()) {
menu.findItem(entry.isDirectory() ? R.id.album_menu_star : R.id.song_menu_star).setTitle(entry.isStarred() ? R.string.common_unstar : R.string.common_star);
}
} else if(selected instanceof Artist) {
if(Util.isOffline(context)) {
inflater.inflate(R.menu.select_artist_context_offline, menu);
}
else {
inflater.inflate(R.menu.select_artist_context, menu);
}
}
}
public boolean onContextItemSelected(MenuItem menuItem, Object selectedItem) {
Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
MusicDirectory.Entry entry = selectedItem instanceof MusicDirectory.Entry ? (MusicDirectory.Entry) selectedItem : null;
List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);
songs.add(entry);
switch (menuItem.getItemId()) {
case R.id.artist_menu_play_now:
downloadRecursively(artist.getId(), false, false, true, false, false);
break;
case R.id.artist_menu_play_shuffled:
downloadRecursively(artist.getId(), false, false, true, true, false);
break;
case R.id.artist_menu_play_last:
downloadRecursively(artist.getId(), false, true, false, false, false);
break;
case R.id.artist_menu_download:
downloadRecursively(artist.getId(), false, true, false, false, true);
break;
case R.id.artist_menu_pin:
downloadRecursively(artist.getId(), true, true, false, false, true);
break;
case R.id.artist_menu_delete:
deleteRecursively(artist);
break;
case R.id.album_menu_play_now:
downloadRecursively(entry.getId(), false, false, true, false, false);
break;
case R.id.album_menu_play_shuffled:
downloadRecursively(entry.getId(), false, false, true, true, false);
break;
case R.id.album_menu_play_last:
downloadRecursively(entry.getId(), false, true, false, false, false);
break;
case R.id.album_menu_download:
downloadRecursively(entry.getId(), false, true, false, false, true);
break;
case R.id.album_menu_pin:
downloadRecursively(entry.getId(), true, true, false, false, true);
break;
case R.id.album_menu_star:
toggleStarred(entry);
break;
case R.id.album_menu_delete:
deleteRecursively(entry);
break;
case R.id.song_menu_play_now:
getDownloadService().clear();
getDownloadService().download(songs, false, true, true, false);
Util.startActivityWithoutTransition(context, DownloadActivity.class);
if(context instanceof SearchActivity) {
context.finish();
}
break;
case R.id.song_menu_play_next:
getDownloadService().download(songs, false, false, true, false);
break;
case R.id.song_menu_play_last:
getDownloadService().download(songs, false, false, false, false);
break;
case R.id.song_menu_download:
getDownloadService().downloadBackground(songs, false);
break;
case R.id.song_menu_pin:
getDownloadService().downloadBackground(songs, true);
break;
case R.id.song_menu_delete:
getDownloadService().delete(songs);
break;
case R.id.song_menu_add_playlist:
addToPlaylist(songs);
break;
case R.id.song_menu_star:
toggleStarred(entry);
break;
case R.id.song_menu_webview:
playWebView(entry);
break;
case R.id.song_menu_play_external:
playExternalPlayer(entry);
break;
case R.id.song_menu_info:
displaySongInfo(entry);
break;
case R.id.song_menu_stream_external:
streamExternalPlayer(entry);
break;
default:
return false;
}
return true;
}
public void replaceFragment(SubsonicFragment fragment, int id) {
context.replaceFragment(fragment, id);
}
public void setPrimaryFragment(boolean primary) {
primaryFragment = primary;
if(primary) {
if(context != null) {
context.setTitle(title);
}
if(invalidated) {
invalidated = false;
refresh(false);
}
}
}
public void invalidate() {
if(primaryFragment) {
refresh(false);
} else {
invalidated = true;
}
}
public DownloadService getDownloadService() {
return context != null ? context.getDownloadService() : null;
}
protected void refresh() {
refresh(true);
}
protected void refresh(boolean refresh) {
}
protected void exit() {
if(context.getClass() != MainActivity.class) {
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Constants.INTENT_EXTRA_NAME_EXIT, true);
Util.startActivityWithoutTransition(context, intent);
} else {
context.stopService(new Intent(context, DownloadServiceImpl.class));
context.finish();
}
}
public void setProgressVisible(boolean visible) {
View view = rootView.findViewById(R.id.tab_progress);
if (view != null) {
view.setVisibility(visible ? View.VISIBLE : View.GONE);
}
}
public void updateProgress(String message) {
TextView view = (TextView) rootView.findViewById(R.id.tab_progress_message);
if (view != null) {
view.setText(message);
}
}
protected synchronized ImageLoader getImageLoader() {
return context.getImageLoader();
}
public synchronized static ImageLoader getStaticImageLoader(Context context) {
return SubsonicActivity.getStaticImageLoader(context);
}
protected void setTitle(CharSequence title) {
this.title = title;
context.setTitle(title);
}
protected void setTitle(int title) {
this.title = context.getResources().getString(title);
context.setTitle(this.title);
}
protected void warnIfNetworkOrStorageUnavailable() {
if (!Util.isExternalStoragePresent()) {
Util.toast(context, R.string.select_album_no_sdcard);
} else if (!Util.isOffline(context) && !Util.isNetworkConnected(context)) {
Util.toast(context, R.string.select_album_no_network);
}
}
protected void onShuffleRequested() {
if(Util.isOffline(context)) {
Intent intent = new Intent(context, DownloadActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
Util.startActivityWithoutTransition(context, intent);
return;
}
View dialogView = context.getLayoutInflater().inflate(R.layout.shuffle_dialog, null);
final EditText startYearBox = (EditText)dialogView.findViewById(R.id.start_year);
final EditText endYearBox = (EditText)dialogView.findViewById(R.id.end_year);
final EditText genreBox = (EditText)dialogView.findViewById(R.id.genre);
final SharedPreferences prefs = Util.getPreferences(context);
final String oldStartYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, "");
final String oldEndYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, "");
final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, "");
startYearBox.setText(oldStartYear);
endYearBox.setText(oldEndYear);
genreBox.setText(oldGenre);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Shuffle By")
.setView(dialogView)
.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(context, DownloadActivity.class);
intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
String genre = genreBox.getText().toString();
String startYear = startYearBox.getText().toString();
String endYear = endYearBox.getText().toString();
SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, startYear);
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, endYear);
editor.putString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, genre);
editor.commit();
Util.startActivityWithoutTransition(context, intent);
}
})
.setNegativeButton(R.string.common_cancel, null);
AlertDialog dialog = builder.create();
dialog.show();
}
public void toggleStarred(final MusicDirectory.Entry entry) {
final boolean starred = !entry.isStarred();
entry.setStarred(starred);
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.setStarred(entry.getId(), starred, context, null);
return null;
}
@Override
protected void done(Void result) {
// UpdateView
Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getTitle()));
}
@Override
protected void error(Throwable error) {
entry.setStarred(!starred);
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
} else {
msg = context.getResources().getString(R.string.starring_content_error, entry.getTitle()) + " " + getErrorMessage(error);
}
Util.toast(context, msg, false);
}
}.execute();
}
public void toggleStarred(final Artist entry) {
final boolean starred = !entry.isStarred();
entry.setStarred(starred);
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.setStarred(entry.getId(), starred, context, null);
return null;
}
@Override
protected void done(Void result) {
// UpdateView
Util.toast(context, context.getResources().getString(starred ? R.string.starring_content_starred : R.string.starring_content_unstarred, entry.getName()));
}
@Override
protected void error(Throwable error) {
entry.setStarred(!starred);
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
} else {
msg = context.getResources().getString(R.string.starring_content_error, entry.getName()) + " " + getErrorMessage(error);
}
Util.toast(context, msg, false);
}
}.execute();
}
protected void downloadRecursively(final String id, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) {
downloadRecursively(id, "", true, save, append, autoplay, shuffle, background);
}
protected void downloadPlaylist(final String id, final String name, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) {
downloadRecursively(id, name, false, save, append, autoplay, shuffle, background);
}
protected void downloadRecursively(final String id, final String name, final boolean isDirectory, final boolean save, final boolean append, final boolean autoplay, final boolean shuffle, final boolean background) {
ModalBackgroundTask<List<MusicDirectory.Entry>> task = new ModalBackgroundTask<List<MusicDirectory.Entry>>(context, false) {
private static final int MAX_SONGS = 500;
@Override
protected List<MusicDirectory.Entry> doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
MusicDirectory root;
if(isDirectory)
root = musicService.getMusicDirectory(id, name, false, context, this);
else
root = musicService.getPlaylist(id, name, context, this);
List<MusicDirectory.Entry> songs = new LinkedList<MusicDirectory.Entry>();
getSongsRecursively(root, songs);
return songs;
}
private void getSongsRecursively(MusicDirectory parent, List<MusicDirectory.Entry> songs) throws Exception {
if (songs.size() > MAX_SONGS) {
return;
}
for (MusicDirectory.Entry song : parent.getChildren(false, true)) {
if (!song.isVideo()) {
songs.add(song);
}
}
for (MusicDirectory.Entry dir : parent.getChildren(true, false)) {
MusicService musicService = MusicServiceFactory.getMusicService(context);
getSongsRecursively(musicService.getMusicDirectory(dir.getId(), dir.getTitle(), false, context, this), songs);
}
}
@Override
protected void done(List<MusicDirectory.Entry> songs) {
DownloadService downloadService = getDownloadService();
if (!songs.isEmpty() && downloadService != null) {
if (!append) {
downloadService.clear();
}
warnIfNetworkOrStorageUnavailable();
if(!background) {
downloadService.download(songs, save, autoplay, false, shuffle);
if(!append) {
Util.startActivityWithoutTransition(context, DownloadActivity.class);
if(context instanceof SearchActivity) {
context.finish();
}
}
}
else {
downloadService.downloadBackground(songs, save);
}
}
}
};
task.execute();
}
protected void addToPlaylist(final List<MusicDirectory.Entry> songs) {
if(songs.isEmpty()) {
Util.toast(context, "No songs selected");
return;
}
new LoadingTask<List<Playlist>>(context, true) {
@Override
protected List<Playlist> doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
return musicService.getPlaylists(false, context, this);
}
@Override
protected void done(final List<Playlist> playlists) {
List<String> names = new ArrayList<String>();
for(Playlist playlist: playlists) {
names.add(playlist.getName());
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Add to Playlist")
.setItems(names.toArray(new CharSequence[names.size()]), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
addToPlaylist(playlists.get(which), songs);
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
@Override
protected void error(Throwable error) {
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
} else {
msg = context.getResources().getString(R.string.playlist_error) + " " + getErrorMessage(error);
}
Util.toast(context, msg, false);
}
}.execute();
}
private void addToPlaylist(final Playlist playlist, final List<MusicDirectory.Entry> songs) {
new SilentBackgroundTask<Void>(context) {
@Override
protected Void doInBackground() throws Throwable {
MusicService musicService = MusicServiceFactory.getMusicService(context);
musicService.addToPlaylist(playlist.getId(), songs, context, null);
return null;
}
@Override
protected void done(Void result) {
Util.toast(context, context.getResources().getString(R.string.updated_playlist, songs.size(), playlist.getName()));
}
@Override
protected void error(Throwable error) {
String msg;
if (error instanceof OfflineException || error instanceof ServerTooOldException) {
msg = getErrorMessage(error);
} else {
msg = context.getResources().getString(R.string.updated_playlist_error, playlist.getName()) + " " + getErrorMessage(error);
}
Util.toast(context, msg, false);
}
}.execute();
}
public void displaySongInfo(final MusicDirectory.Entry song) {
Integer bitrate = null;
String format = null;
long size = 0;
try {
DownloadFile downloadFile = new DownloadFile(context, song, false);
File file = downloadFile.getCompleteFile();
if(file.exists()) {
MediaMetadataRetriever metadata = new MediaMetadataRetriever();
metadata.setDataSource(file.getAbsolutePath());
String tmp = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
bitrate = Integer.parseInt((tmp != null) ? tmp : "0") / 1000;
format = FileUtil.getExtension(file.getName());
size = file.length();
if(Util.isOffline(context)) {
song.setGenre(metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE));
String year = metadata.extractMetadata(MediaMetadataRetriever.METADATA_KEY_YEAR);
song.setYear(Integer.parseInt((year != null) ? year : "0"));
}
}
} catch(Exception e) {
Log.i(TAG, "Device doesn't properly support MediaMetadataRetreiver");
}
String msg = "";
if(!song.isVideo()) {
msg += "Artist: " + song.getArtist() + "\nAlbum: " + song.getAlbum();
}
if(song.getTrack() != null && song.getTrack() != 0) {
msg += "\nTrack: " + song.getTrack();
}
if(song.getGenre() != null && !"".equals(song.getGenre())) {
msg += "\nGenre: " + song.getGenre();
}
if(song.getYear() != null && song.getYear() != 0) {
msg += "\nYear: " + song.getYear();
}
if(!Util.isOffline(context)) {
msg += "\nServer Format: " + song.getSuffix();
if(song.getBitRate() != null && song.getBitRate() != 0) {
msg += "\nServer Bitrate: " + song.getBitRate() + " kpbs";
}
}
if(format != null && !"".equals(format)) {
msg += "\nCached Format: " + format;
}
if(bitrate != null && bitrate != 0) {
msg += "\nCached Bitrate: " + bitrate + " kpbs";
}
if(size != 0) {
msg += "\nSize: " + Util.formatBytes(size);
}
if(song.getDuration() != null && song.getDuration() != 0) {
msg += "\nLength: " + Util.formatDuration(song.getDuration());
}
new AlertDialog.Builder(context)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(song.getTitle())
.setMessage(msg)
.show();
}
protected void playWebView(MusicDirectory.Entry entry) {
int maxBitrate = Util.getMaxVideoBitrate(context);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(maxBitrate, context, entry.getId())));
startActivity(intent);
}
protected void playExternalPlayer(MusicDirectory.Entry entry) {
if(!entryExists(entry)) {
Util.toast(context, R.string.download_need_download);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(entry.getPath()), "video/*");
List<ResolveInfo> intents = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(intents != null && intents.size() > 0) {
startActivity(intent);
}else {
Util.toast(context, R.string.download_no_streaming_player);
}
}
}
protected void streamExternalPlayer(MusicDirectory.Entry entry) {
int maxBitrate = Util.getMaxVideoBitrate(context);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoStreamUrl(maxBitrate, context, entry.getId())), "video/*");
List<ResolveInfo> intents = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(intents != null && intents.size() > 0) {
startActivity(intent);
} else {
Util.toast(context, R.string.download_no_streaming_player);
}
}
protected boolean entryExists(MusicDirectory.Entry entry) {
DownloadFile check = new DownloadFile(context, entry, false);
return check.isCompleteFileAvailable();
}
public void deleteRecursively(Artist artist) {
File dir = FileUtil.getArtistDirectory(context, artist);
Util.recursiveDelete(dir);
if(Util.isOffline(context)) {
refresh();
}
}
public void deleteRecursively(MusicDirectory.Entry album) {
File dir = FileUtil.getAlbumDirectory(context, album);
Util.recursiveDelete(dir);
if(Util.isOffline(context)) {
refresh();
}
}
}
|