Developers

Functions of AirWire


Main functions:
  • Search in LAN devices to play media content (DLNA DMR, Dune players, Chromecast);
  • Sending content (video, photos, audio) to the playback device;
  • Playback Control;
  • Searching for installed applications on your mobile device for viewing media content;
  • Built-in player for viewing media content.
Additional functions:
  • Search in LAN DLNA servers.
  • Browsing by DLNA servers.
  • Integration with popular services Dropbox, Google Drive...

Integration with AirWire


To use AirWire in your application, perform the following actions:
  1. Download AirWireSDK.jar
  2. Add AirWireSDK.jar as a library to your project
  3. Add access permission for AirWire playlists in AndroidManifest.xml of your application
  • <?xml version="1.0" encoding="utf-8"?>
  • <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  •     package="com.example.airwireexample"
  •     android:versionCode="1"
  •     android:versionName="1.0" >
  •     <uses-sdk
  •         android:minSdkVersion="8"
  •         android:targetSdkVersion="17" />
  •     <application
  •         android:icon="@drawable/ic_launcher"
  •         android:label="@string/app_name"
  •         android:theme="@style/AppTheme" >
  •         <activity
  •             android:name="com.example.airwireexample.ExampleActivity"
  •             android:label="@string/app_name" >
  •             <intent-filter>
  •                 <action android:name="android.intent.action.MAIN" />
  •  
  •                 <category android:name="android.intent.category.LAUNCHER" />
  •             </intent-filter>
  •         </activity>
  •     </application>
  •  
  •     <uses-permission android:name="tv.airwire.PLAYLIST_ACCESS" />
  •  
  • </manifest>

Checking access to AirWire


Before your application starts interacting with AirWire, you should check if AirWire is installed in the device. For this purpose, you can use class AirWireInstallationHelper, which is part of AirWireSDK.jar. In this case, the check will be as follows:
  • if (!AirWireInstallationHelper.isInstalled(this)) {
  •     AirWireInstallationHelper.showInstallDialog(this);
  • }
The above code checks availability of AirWire among the applications installed in the device, and if it is absent the code shows a dialogue window requesting the installation of the application from Google Play. If the user agrees, the Google Play page will be opened with a description of AirWire, from which the user can directly install the application.


Note: the showInstallDialog() method shows the dialogue in English, therefore if you wish to show this dialogue in the user's local language, you need to impleFor the interaction with AirWire, the AirWireConnector class is used, which contains the following methods
  • Intent intent = new Intent(Intent.ACTION_VIEW);
  • intent.setData(AirWireInstallationHelper.getAirWireMarketUri());
  • intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  • activity.startActivity(intent);

Interaction with AirWire


For the interaction with AirWire, the AirWireConnector class is used, which contains the following methods:
  • playFile() - Starts AirWire and transfers to it the media file which should be played back;
  • startPlaylist() - Creates a playlist, selects the media file which should be played back first, starts AirWire and displays the playlist;
  • addFileToPlayList() - Adds a file to the playlist;
  • removeFileFromPlaylist() - Removes a file from the playlist;
  • subscribeOnPlaylistUpdates() - Subscribes for playlist update notifications;
  • unsubscribeFromPlaylistUpdates() - Unsubscribes from playlist update notifications;
  • showPlayer() - Starts AirWire.

Playback of one media file


The simplest method of interaction with the AirWire application is the playback of a single media file. For this purpose, it is enough to call the playFile() method and to transfer to it an instance of the MediaFile.

The MediaFile class contains all the information necessary for AirWire about the content which you transfer to the application (direct links, link to preview image, file identifier, data type, etc.). To simplify the data transformation for your application in accordance with the format defined in the MediaFile class, AirWireSDK.jar has the MediaFileBuilder class. The minimum parameters for this class, with which it can create the MediaFile object, are a direct link to it's content and it's MIME-type.
  • public static MediaFile createTestVideoFile(){
  •  
  •     // Creates Object MediaFileBuilder
  •     // on the basis of a direct link to the video and the data type,
  •     // and specifies the duration of the media file
  •     // (recommended parameter for video and audio files)
  •     MediaFileBuilder fileBuilder = new MediaFileBuilder{
  •         "http://clips.vorwaerts-gmbh.de/VfE_html.mp4",
  •         "video/mp4",
  •         "00:01:00");
  •  
  •     // Sets a unique identifier for the file
  •     // (recommended parameter)
  •     // Generated by default on the basis of the link
  •     // to the content
  •     fileBuilder.setContentId("VfEIovdRe");
  •  
  •     // Sets the name of the media file
  •     // Name is by default set on the basis of
  •     // the link to the content
  •     fileBuilder.setTitle("Video For Everybody");
  •  
  •     // Sets the link for the content preview image
  •     fileBuilder.setPreviewImage("http://camendesign.com/code/video_for_everybody/screenshots/ipad.png");
  •  
  •     // Sets the content type
  •     // Determined by default on the basis of
  •     // the specified MIME-type
  •     fileBuilder.setType(MediaType.VIDEO);
  •  
  •     // Creates an instance of MediaFile on the basis of specified data
  •     return fileBuilder.build();
  • }
The MediaFile object can have a few links(for example, video can have several resolutions). And the code to create such an object can be as follow:
  • public static MediaFile createVideoMultiLinkFile(){
  •     // Creates the media resource which stores a few
  •     // links to various resolutions of one video
  •     MediaResource resource = new MediaResource(
  •         ContentFeatture.getProtocol("video/mp4"), "00:04:21");
  •  
  •     // Adding a few links
  •     resource.putUrl(QualityType.HD_QUALITY, "http://...");
  •     resource.putUrl(QualityType.MOBILE_QUALITY, "http://...");
  •     resource.putUrl(QualityType.LOW_QUALITY, "http://...");
  •     resource.putUrl(QualityType.MIDDLE_QUALITY, "http://...");
  •  
  •     // Sets the quality by default
  •     resource.setDefaultQuality(QualityType.MIDDLE_QUALITY);
  •  
  •     // Creates an instance of MediaFile
  •     return new MediaFileBuilder(resource, "video/mp4")
  •         .setContentId(163772799).setTitle("Title")
  •         .setPreviewImage("http://...").build();
  • }

Work with playlists


To play back a few files (a playlist) sequentially with AirWire, you should call the startPlaylist() method and to transfer to it the list of media files and the file index from which it is necessary to start playing back as arguments. The startPlaylist() method should return the URI of the created playlist. This URI can be used by you later to add new files to the playlist (addFileToPlaylist()), remove files from the playlist (removeFileFromPlaylist()), see the current playback position.

To ensure that your application receives playlist status update notifications, you should implement Class android.database.ContentObserver and transfer an instance of this class as an argument of Method subscribeOnPlaylistUpdates(). So, if the playlist data is changed (for example, next file in the list is played back), Method onChange() will be called in Object ContentObserver. Below there is a code displaying the file list in TextView and showing the current playback position in the playlist.
  • package com.example.airwireexample;
  •  
  • import tv.airwire.connector.ContentContract;
  • import android.content.ContentResolver;
  • import android.database.ContentObserver;
  • import android.database.Cursor;
  • import android.net.Uri;
  • import android.os.Handler;
  • import android.widget.TextView;
  •  
  • public class PlayListObserver extends ContentObserver {
  •  
  •     private final TextView textView;
  •     private final Uri playListUri;
  •  
  •     // Creates the object which monitors changes in the playlist.
  •     // It rreveives a playlist URI and an instance of TextView
  •     // to show changesдля отображения изменений
  •     public PlayListObserver(final Uri playListUri, final TextView textView) {
  •         super(new Handler());
  •         this.textView = textView;
  •         this.playList = playListUri;
  •     }
  •  
  •     // Method which is called if data changes in the playlist
  •     @Override
  •     public void onChange(boolean selfChange) {
  •         ContentResolver resolver = textView.getContext().getContentResolver();
  •         showPlayList(resolver.query(playListuri, null, null, null, null));
  •     }
  •  
  •     // Displays the playlist
  •     private void showPlayList(final Cursor cursor) {
  •         StringBuilder playListBuilder = new StringBuilder("PLAYLIST\n");
  •         if (cursor != null && cursor.moveToFirst()) {
  •             do {
  •                 playListBuilder.append(getStringColumn(cursor,
  •                         ContentContract.ContentColumns.TITLE));
  •                 playListBuilder.append("\t");
  •                 playListBuilder.append(getState(cursor));
  •                 playListBuilder.append('\n');
  •             } while (cursor.moveToNext());
  •         }
  •         textView.setText(playListBuilder.toString());
  •     }
  •  
  •     private String getStringColumn(final Cursor data, final String columnName) {
  •         private String getStringColumn(final Cursor data, final String columnName) {
  •             return data.getString(data.getColumnIndex(columnName));
  •         }
  •  
  •     private String getStringColumn(final Cursor data, final String columnName) {
  •         return data.getString(data.getColumnIndex(columnName));
  •     }
  •  
  •     // Checks the file playback attribute
  •     private String getState(final Cursor data) {
  •         return data.getInt(data.getColumnIndex(ContentContract.ContenntColumns.PLAYING)) == 1 ? "PLAYING"
  •                 : "-";
  •     }
  • }

To use AirWire in your application, download airwire-sdk.dll and add it as a library to your project.

If an AirWire application is not installed on user's phone, Windows Phone will offer to find it in WinStore.

Interaction with AirWire


For the interaction with AirWire, the AirWireConnector class is used, which contains the following methods:
  • PlayFileAsync() - Starts AirWire and transfers to it the media file which should be played back;
  • StartPlaylistAsync() - Starts AirWire and displays the playlist;
  • AddFileToPlayList() - Adds a file to the playlist;
  • RemoveFileFromPlaylist() - Removes a file from the playlist;
  • ShowPlayerAsync() - Starts AirWire.

Playback of one media file


The simplest method of interaction with the AirWire application is the playback of a single media file. For this purpose, it is enough to call the PlayFileAsync() method and to transfer to it an instance of the MediaFile. The MediaFile class contains all the information necessary for AirWire about the content which you transfer to the application (direct links, link to preview image, file identifier, data type, etc.). To simplify the data transformation for your application in accordance with the format defined in the MediaFile class, airwire-sdk.dll has the MediaFileBuilder class. The minimum parameters for this class, with which it can create the MediaFile object, are a direct link to it's content and it's MIME-type.
  • public static MediaFile CreateTestVideoFile(){
  •     // Creates Object MediaFileBuilder
  •     // on the basis of a direct link to the video and the data type,
  •     // and specifies the duration of the media file
  •     // (recommended parameter for video and audio files)
  •     MediaFileBuilder fileBuilder = new MediaFileBuilder(
  •         "http://clips.vorwaerts-gmbh.de/VfE_html.mp4",
  •         "video/mp4",
  •         "00:01:00");
  •     // Sets a unique identifier for the file
  •     // (recommended parameter)
  •     // Generated by default on the basis of the link
  •     // to the content
  •     fileBuilder.ContentId = "VfEIovdRe";
  •     // Sets the name of the media file
  •     // Name is by default set on the basis of
  •     // the link to the content
  •     fileBuilder.Title = "Video For Everybody";
  •     // Sets the link for the content preview image
  •     fileBuilder.PreviewImageUrl = "http://camendesign.com/code/video_for_everybody/screenshots/ipad.png";
  •     // Sets the content type
  •     // Determined by default on the basis of
  •     // the specified MIME-type
  •     fileBuilder.Type = MediaType.VIDEO;
  •     // Creates an instance of MediaFile on the basis of specified data
  •     return fileBuilder.Build();
  • }
Объект MediaFile может содержать несколько ссылок (например, видео может иметь несколько разрешений). Тогда код создания такого объекта может выглядеть следующим образом:
  • public static MediaFile CreateVideoMultiLinkFile(){
  •     // Creates the media resource which stores a few
  •     // links to various resolutions of one video
  •     MediaResource resource = new MediaResource(
  •     ContentFeatture.getProtocol("video/mp4"), "00:04:21");
  •     // Adding a few links
  •     resource.PutUrl(QualityType.HD_QUALITY, "http://...");
  •     resource.PutUrl(QualityType.MOBILE_QUALITY, "http://...");
  •     resource.PutUrl(QualityType.LOW_QUALITY, "http://...");
  •     resource.PutUrl(QualityType.MIDDLE_QUALITY, "http://...");
  •     // Sets the quality by default
  • resource.DefaultQuality = QualityType.MIDDLE_QUALITY;
  •     // Creates an instance of MediaFile
  •     return new MediaFileBuilder(resource, "video/mp4"){
  •         ContentId = "163772799",
  •     Title = "Title",
  •         PreviewImageUrl = "http://..."
  • }.Build();
  • }

Work with playlists


To play back a few files (a playlist) sequentially with AirWire, you should call the startPlaylist() method and to transfer to it the list of media files and the file index from which it is necessary to start playing back as arguments. The startPlaylist() method should return the URI of the created playlist. This URI can be used by you later to add new files to the playlist (addFileToPlaylist()), remove files from the playlist (removeFileFromPlaylist()), see the current playback position.

Feedback

Close