Zapstreak Android Integration Guideline (Version: 14.02.2013)

  1. Set up your working environment
  2. Class Overview
  3. Quick Integaration
  4. Advanced Integration

Set up your working environment

1. Add zapstreak.jar to your application’s classpath

If you’re using Eclipse, drop the jar into your libs folder, modify your Java Build Path, and choose Add External JAR. If you’re using the SDK tools directly, and the Ant task will pick it up.

2. Configure AndroidManifest.xml

Required permissions to work with the network and WiFi are:

  • android.permission.INTERNET,
  • android.permission.ACCESS_NETWORK_STATE,
  • android.permission.ACCESS_WIFI_STATE,
  • android.permission.READ_LOGS.
<!-- Zapstreak required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />

<application>
  <activity>

  </activity>

  <!-- Zapstreak license key declaration -->
  <meta-data android:name="zapstreak_license" android:value="PUT_YOUR_LICENSE_KEY_HERE" />
</application>

Required license key. Please insert it into the <application></application> range.

<meta-data android:name="zapstreak_license" android:value="PUT_YOUR_LICENSE_KEY_HERE" />

Class Overview

Package Class Description
com.fusionsheep.dlna
RendererFinder Finds connected media players device.
RendererDevice An object contains information about the media player device.
RendererAction An object that performs actions on the media player device.
com.fusionsheep.dlna.listener
OnRendererFinderListener A simple interface for receiving notifications about discovered media playback devices.
OnRendererActionListener A simple interface for receiving notifications about actions on the media playback device.
OnRendererVolumeListener A simple interface for receiving notifications about volume on the media playback device.
com.fusionsheep.view
ZapstreakButtonView The view displaying the Zapstreak Button.
OnDeviceSelectListener A simple interface for receiving notifications about the selected connected media playback device.

Quick Integration

Use case: simple implementation that will enhance your player with one button and the ability to send multimedia to connected media playback devices.

1. Find connected media players.

In your media player layout XML file please add the code that is shown below. Remember to change the button background android:background to fit your visual design.

<com.fusionsheep.view.ZapstreakButtonView
          android:id="@+id/bt_zapstreak"
          android:layout_width="60dp"
          android:layout_height="60dp"
          android:background="@drawable/zapstreak_button" />

In your media player.

import com.fusionsheep.dlna.RendererAction;
import com.fusionsheep.dlna.RendererDevice;
import com.fusionsheep.dlna.RendererFinder;
import com.fusionsheep.dlna.RendererFinder.LicenseExpiredException;
import com.fusionsheep.dlna.RendererFinder.LicenseNetworkMissingException;
import com.fusionsheep.dlna.RendererFinder.LicenseNumberException;
import com.fusionsheep.view.ZapstreakButtonView;
import com.fusionsheep.view.ZapstreakButtonView.OnDeviceSelectListener;



public class MediaPlayerActivity extends Activity
{
   //zapstreak button
   private ZapstreakButtonView mZapstreakButton = null;
   //finder
   private RendererFinder mFinder = null;
   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
       try {
        mFinder = RendererFinder.instance(getBaseContext());
      } catch (LicenseExpiredException e1) {
        e1.printStackTrace();
      } catch (LicenseNumberException e1) {
        e1.printStackTrace();
      } catch (LicenseNetworkMissingException e1) {
        e1.printStackTrace();
      }

       mZapstreakButton = (ZapstreakButtonView)findViewById(R.id.bt_zapstreak);
       mZapstreakButton.setRendererFinder(mFinder);
       mZapstreakButton.setOnDeviceSelectListener(new OnDeviceSelectListener() {
           @Override
           public void onDeviceSelect(RendererDevice device)
           {
               //this event will be fired when users select device

               //perform action on selected device
               RendererAction action = new RendererAction(getBaseContext(), device);

               //play media stored in the phone memory
               action.playLocal("/music/test.mp3");
           }            
       });
   }
}

Advanced Integration

Use case: build or customize your media player.

1. Find devices: TV or other connected media players.

Insert a call to RendererFinder.instance(Context) passing it a reference to a Context object (such as an Activity or Service).

Setup a listener that will be called when device like TV or other connected media player are found. You can add devices to a ListView or a GridView.

Start the finder and stop the finder when the Activity is destroyed.

package com.zapstreak.helloworld;

import com.fusionsheep.dlna.RendererFinder;
import com.fusionsheep.dlna.RendererFinder.LicenseExpiredException;
import com.fusionsheep.dlna.RendererFinder.LicenseNetworkMissingException;
import com.fusionsheep.dlna.RendererFinder.LicenseNumberException;
import com.fusionsheep.dlna.RendererFinder.OnRendererFinderListener;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

   private RendererFinder mFinder = null;

   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
   }

   @Override
   protected void onResume() {
      super.onResume();

      try {
        mFinder = RendererFinder.instance(getBaseContext());
      } catch (LicenseExpiredException e1) {
        // FIXME: React to the license expiration.
      } catch (LicenseNumberException e1) {
        // FIXME: React to the license number exception.
      } catch (LicenseNetworkMissingException e1) {
        // FIXME: React to the network missing.
      }

      mFinder.setOnRendererFindListener(new OnRendererFinderListener() {
        @Override
        public void onFind(RendererDevice device) {
            // TODO: Your code here — for example add devices
            // to the adapter.
            }
      });
      mFinder.findStart();
   }
   @Override
   protected void onDestroy() {
       mFinder.findStop();
       super.onDestroy();
   }
 }

2. Playing content on a device.

RendererDevice device; //selected device
RendererAction action  = new RendererAction(mContext,device);


action.setOnRendererAction(mActionListener);
action.setOnVolumeAction(mVolumeListener);


//action status listener
OnRendererActionListener mActionListener = new OnRendererActionListener()
{
      @Override
      public void onInvalidPathOrUrl(RendererDevice device)
      {
           //the url or path of the file you are trying to play is invalid
      }

      @Override
      public void onPlaying(RendererDevice device)
      {
          //playing media file
      }

      @Override
      public void onPlayPosition(RendererDevice device,
          int iRealTime, String szRealTime,
          int iTrackDuration, String szTrackDuration)
      {
           //media file time seek position and total duration
      }

      @Override
      public void onPaused(RendererDevice device)
      {
           //playing of media file paused
      }

      @Override
      public void onStopped(RendererDevice device)
      {
           //playing of media file stopped
      }

      @Override
      public void onTransitioning(RendererDevice device)
      {
           //the media file is being loaded
      }

      @Override
      public void onNoMediaPresent(RendererDevice device)
      {
           //error while playing content
      }       
      @Override
      public void onUnableToPlay(RendererDevice device)
      {
           //error when device is unable to play your file
      }

};

//volume listener
OnRendererVolumeListener mVolumeListener = new OnRendererVolumeListener()
{
      @Override
      public void onVolumeSet(RendererDevice device, int iVolume)
      {
      }

      @Overridex
      public void onVolumeGet(RendererDevice device, int iVolume)
      {
           //here you will get volume level after calling action.volumeGet()
      }        
};

//play file stored in the phone sdcard
action.playLocal(“/movie/trailer.mp4”);

//play file stored in the phone sdcard with title, artist and album name
action.playLocal(“/movie/trailer.mp4,”Title”,”Artist”,”Album”);

//play remote file
action.playRemote(“http://foobar.com/test.mp4”);

//play remote file with title, artist and album name
action.playRemote(“http://foobar.com/test.mp4”,”Title”,”Artist”,”Album”);

//seek time to 61 sec
action.seek(61);

//get device volume
action.volumeGet();

//set device volume
action.volumeSet(60);

The code from this scenario is mostly taken from our “Hello World” application, which you can find on Bitbucket: https://bitbucket.org/fusionsheep/zapstreak_android_helloworld.

Go Top ^