From adf15c58d390eace444149e9ab90acbcf456ae9c Mon Sep 17 00:00:00 2001 From: lado Date: Wed, 7 Sep 2011 09:50:16 +0200 Subject: added streaming support for external players. Fixed a npe in ChannelListActivity --- .../de/bjusystems/vdrmanager/data/Preferences.java | 18 ++++- .../vdrmanager/gui/ChannelListActivity.java | 81 ++++++++++++---------- .../bjusystems/vdrmanager/gui/VideoActivity.java | 67 ------------------ 3 files changed, 62 insertions(+), 104 deletions(-) delete mode 100644 vdrmanager/src/de/bjusystems/vdrmanager/gui/VideoActivity.java (limited to 'vdrmanager/src') diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java index 3e1fc8a..9bb7c13 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/data/Preferences.java @@ -43,6 +43,18 @@ public class Preferences { private int timerDefaultLifetime; /** user defined epg search times */ private String epgSearchTimes; + + private int streamPort = 3000; + + public int getStreamPort() { + return streamPort; + } + + public String getStreamFormat() { + return streamFormat; + } + + private String streamFormat = "TS"; /** Properties singleton */ private static Preferences thePrefs; @@ -226,11 +238,13 @@ public class Preferences { final Preferences prefs = new Preferences(); - prefs.svdrpHost = getString(context, sharedPrefs, R.string.vdr_host_key, "10.0.2.2"); + prefs.svdrpHost = getString(context, sharedPrefs, R.string.vdr_host_key, "127.0.0.1"); prefs.svdrpPort = getInt(context, sharedPrefs, R.string.vdr_port_key, 6419); prefs.password = getString(context, sharedPrefs, R.string.vdr_password_key, ""); prefs.ssl = getBoolean(context, sharedPrefs, R.string.vdr_ssl_key, false); - + prefs.streamPort = getInt(context, sharedPrefs, R.string.vdr_stream_port, 3000); + prefs.streamFormat= getString(context, sharedPrefs, R.string.vdr_stream_format, "TS"); + prefs.aliveCheckEnabled = getBoolean(context, sharedPrefs, R.string.alive_check_enabled_key, false); prefs.aliveCheckInterval = getInt(context, sharedPrefs, R.string.alive_check_interval_key, 60); diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java index ac12efd..3d61b56 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/ChannelListActivity.java @@ -5,6 +5,7 @@ import java.util.List; import android.app.Activity; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -26,12 +27,12 @@ import de.bjusystems.vdrmanager.utils.svdrp.SvdrpEvent; import de.bjusystems.vdrmanager.utils.svdrp.SvdrpException; /** - * This class is used for showing what's - * current running on all channels + * This class is used for showing what's current running on all channels + * * @author bju */ -public class ChannelListActivity extends Activity - implements OnItemClickListener, SvdrpAsyncListener { +public class ChannelListActivity extends Activity implements + OnItemClickListener, SvdrpAsyncListener { ChannelClient channelClient; ChannelAdapter adapter; @@ -53,17 +54,17 @@ public class ChannelListActivity extends Activity // register context menu registerForContextMenu(listView); - // create channel list channels = new ArrayList(); listView.setOnItemClickListener(this); } - public void onItemClick(final AdapterView parent, final View view, final int position, final long id) { + public void onItemClick(final AdapterView parent, final View view, + final int position, final long id) { // find and remember item - final Channel channel = (Channel) parent.getAdapter().getItem(position); + final Channel channel = adapter.getItem(position); final VdrManagerApp app = (VdrManagerApp) getApplication(); app.setCurrentChannel(channel); app.setChannels(channels); @@ -74,8 +75,6 @@ public class ChannelListActivity extends Activity startActivity(intent); } - - @Override protected void onResume() { super.onResume(); @@ -100,7 +99,8 @@ public class ChannelListActivity extends Activity channelClient = new ChannelClient(); // create background task - final SvdrpAsyncTask> task = new SvdrpAsyncTask>(channelClient); + final SvdrpAsyncTask> task = new SvdrpAsyncTask>( + channelClient); // create progress progress = new SvdrpProgressDialog(this, channelClient); @@ -128,7 +128,7 @@ public class ChannelListActivity extends Activity break; case FINISHED: channels.addAll(channelClient.getResults()); - for(final Channel channel : channels) { + for (final Channel channel : channels) { adapter.add(channel); } progress = null; @@ -142,46 +142,57 @@ public class ChannelListActivity extends Activity } @Override - public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) { + public void onCreateContextMenu(final ContextMenu menu, final View v, + final ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); if (v.getId() == R.id.channel_list) { - final MenuInflater inflater = getMenuInflater(); - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; + final MenuInflater inflater = getMenuInflater(); + final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; - // set menu title - final Channel item = adapter.getItem(info.position); - menu.setHeaderTitle(item.getName()); + // set menu title + final Channel item = adapter.getItem(info.position); + menu.setHeaderTitle(item.getName()); - inflater.inflate(R.menu.channel_list_item_menu, menu); + inflater.inflate(R.menu.channel_list_item_menu, menu); } } - - @Override public boolean onContextItemSelected(final MenuItem item) { - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); - final Channel channel = adapter.getItem(info.position); - - switch (item.getItemId()) { - case R.id.channel_item_menu_epg: - onItemClick(null, null, info.position, 0); - break; - case R.id.channel_item_menu_stream: - // show live stream - showStream(channel); - break; + final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item + .getMenuInfo(); + final Channel channel = adapter.getItem(info.position); + + switch (item.getItemId()) { + case R.id.channel_item_menu_epg: + onItemClick(null, null, info.position, 0); + break; + case R.id.channel_item_menu_stream: + // show live stream + showStream(channel); + break; } return true; } + private String getStreamUrl(Channel c) { + //"http://192.168.1.119:3000/TS/" + StringBuilder sb = new StringBuilder(); + Preferences p = Preferences.getPreferences(); + sb.append("http://").append(p.getSvdrpHost()).append(":") + .append(p.getStreamPort()).append("/") + .append(p.getStreamFormat()).append("/") + .append(c.getNumber()); + return sb.toString(); + } private void showStream(final Channel channel) { - // show stream - final Intent intent = new Intent(); - intent.setClass(this, VideoActivity.class); - startActivity(intent); + + String url = getStreamUrl(channel); + final Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.parse(url.toString()),"video/*"); + startActivityForResult(intent, 1); } } diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VideoActivity.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/VideoActivity.java deleted file mode 100644 index 6e17d15..0000000 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/VideoActivity.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.bjusystems.vdrmanager.gui; - -import android.app.Activity; -import android.net.Uri; -import android.os.Bundle; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.MediaController; -import android.widget.VideoView; -import de.bjusystems.vdrmanager.R; -import de.bjusystems.vdrmanager.data.Preferences; - -/** - * This class is used for showing what's - * current running on all channels - * @author bju - */ -public class VideoActivity extends Activity - implements OnClickListener { - - Preferences prefs; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Attach view - setContentView(R.layout.video); - - // set stream - final VideoView videoView = (VideoView) findViewById(R.id.video_video); - final MediaController mediaController = new MediaController(this); - mediaController.setAnchorView(videoView); - final Uri video = Uri.parse("http://192.168.178.20:3000/1"); - videoView.setMediaController(mediaController); - videoView.setVideoURI(video); - videoView.start(); - - // register button - final Button button = (Button) findViewById(R.id.video_button); - button.setOnClickListener(this); - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - } - - public void onClick(final View v) { - - // Save search parameters -// final EpgSearchParams search = new EpgSearchParams(); -// search.setTitle(text.getText().toString()); -// ((VdrManagerApp)getApplication()).setCurrentSearch(search); - - // show timer details -// final Intent intent = new Intent(); -// intent.setClass(this, VdrManagerActivity.class); -// startActivity(intent); - } -} -- cgit v1.2.3