X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/5dc43aab3cc1243f9989dd6a0c7dd3350c3f709b..9826f99c41c0685ee15540b4544997c8da8c0eb4:/src/com/owncloud/android/media/MediaService.java diff --git a/src/com/owncloud/android/media/MediaService.java b/src/com/owncloud/android/media/MediaService.java index 992bc7dd..15fad667 100644 --- a/src/com/owncloud/android/media/MediaService.java +++ b/src/com/owncloud/android/media/MediaService.java @@ -1,5 +1,8 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. +/** + * ownCloud Android client application + * + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -18,38 +21,42 @@ package com.owncloud.android.media; import android.accounts.Account; +import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; import android.media.MediaPlayer.OnPreparedListener; +import android.net.Uri; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.WifiLock; import android.os.IBinder; import android.os.PowerManager; +import android.support.v7.app.AlertDialog; import android.widget.Toast; import java.io.IOException; -import com.owncloud.android.Log_OC; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.accounts.AccountUtils; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; + /** * Service that handles media playback, both audio and video. * * Waits for Intents which signal the service to perform specific operations: Play, Pause, * Rewind, etc. - * - * @author David A. Velasco */ public class MediaService extends Service implements OnCompletionListener, OnPreparedListener, OnErrorListener, AudioManager.OnAudioFocusChangeListener { @@ -208,6 +215,25 @@ public class MediaService extends Service implements OnCompletionListener, OnPre return context.getString(messageId); } + public static AlertDialog.Builder streamWithExternalApp(final String uri, final Activity activity){ + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setMessage(activity.getString(R.string.stream_expose_password)) + .setPositiveButton(activity.getString(R.string.common_yes), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(uri)); + activity.startActivity(i); + } + }) + .setNegativeButton(activity.getString(R.string.common_no), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + } + }); + return builder; + } + /** @@ -217,6 +243,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre */ @Override public void onCreate() { + super.onCreate(); Log_OC.d(TAG, "Creating ownCloud media service"); mWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)). @@ -427,12 +454,12 @@ public class MediaService extends Service implements OnCompletionListener, OnPre releaseResources(false); // release everything except MediaPlayer try { - if (mFile == null) { - Toast.makeText(this, R.string.media_err_nothing_to_play, Toast.LENGTH_LONG).show(); - processStopRequest(true); - return; +// if (mFile == null) { +// Toast.makeText(this, R.string.media_err_nothing_to_play, Toast.LENGTH_LONG).show(); +// processStopRequest(true); +// return; - } else if (mAccount == null) { + if (mAccount == null) { Toast.makeText(this, R.string.media_err_not_in_owncloud, Toast.LENGTH_LONG).show(); processStopRequest(true); return; @@ -441,12 +468,12 @@ public class MediaService extends Service implements OnCompletionListener, OnPre createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); String url = mFile.getStoragePath(); - /* Streaming is not possible right now + // Streaming is not possible right now if (url == null || url.length() <= 0) { url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath(); } mIsStreaming = url.startsWith("http:") || url.startsWith("https:"); - */ + mIsStreaming = false; mPlayer.setDataSource(url); @@ -483,6 +510,8 @@ public class MediaService extends Service implements OnCompletionListener, OnPre Log_OC.e(TAG, "IllegalArgumentException " + mAccount.name + mFile.getRemotePath(), e); Toast.makeText(this, String.format(getString(R.string.media_err_unexpected), mFile.getFileName()), Toast.LENGTH_LONG).show(); processStopRequest(true); + } catch (AccountUtils.AccountNotFoundException e) { + e.printStackTrace(); } } @@ -636,6 +665,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre mState = State.STOPPED; releaseResources(true); giveUpAudioFocus(); + super.onDestroy(); }