Video 360

You can build a application with a video 360.

video 360

You can download the project here

The first step:

We have to put in build.gradle, in dependences this line:

1
compile files('src/main/libs/panframe-1.9.jar')

Then we have to add video in src/raw

Now in our activity we put this code:

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
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.SeekBar;
 
import com.panframe.android.lib.PFAsset;
import com.panframe.android.lib.PFAssetObserver;
import com.panframe.android.lib.PFAssetStatus;
import com.panframe.android.lib.PFNavigationMode;
import com.panframe.android.lib.PFObjectFactory;
import com.panframe.android.lib.PFView;
 
import java.util.Timer;
import java.util.TimerTask;
 
public class MainActivity extends ActionBarActivity implements PFAssetObserver, SeekBar.OnSeekBarChangeListener {
 
    PFView mPfview;
    PFAsset mPfasset;
    PFNavigationMode mCurrentNavigationMode = PFNavigationMode.MOTION;
 
    boolean             mUpdateThumb = true;;
    Timer mScrubberMonitorTimer;
 
    ViewGroup mFrameContainer;
    Button mStopButton;
    Button              mPlayButton;
    Button              mTouchButton;
    SeekBar             mScrubber;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
 
        mFrameContainer = (ViewGroup) findViewById(R.id.framecontainer);
        mFrameContainer.setBackgroundColor(0xFF000000);
 
        mPlayButton = (Button)findViewById(R.id.playbutton);
        mStopButton = (Button)findViewById(R.id.stopbutton);
        mTouchButton = (Button)findViewById(R.id.touchbutton);
        mScrubber = (SeekBar)findViewById(R.id.scrubber);
 
        mPlayButton.setOnClickListener(playListener);
        mStopButton.setOnClickListener(stopListener);
        mTouchButton.setOnClickListener(touchListener);
        mScrubber.setOnSeekBarChangeListener(this);
 
        mScrubber.setEnabled(false);
 
        loadVideo("android.resource://" + getPackageName() + "/" + R.raw.skyrim360);
 
        showControls(true);
        mPfasset.play();
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
 
        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }
 
        return super.onOptionsItemSelected(item);
    }
 
    /**
     * Show/Hide the playback controls
     *
     * @param  bShow  Show or hide the controls. Pass either true or false.
     */
    public void showControls(boolean bShow)
    {
        int visibility = View.GONE;
 
        if (bShow)
            visibility = View.VISIBLE;
 
        mPlayButton.setVisibility(visibility);
        mStopButton.setVisibility(visibility);
        mTouchButton.setVisibility(visibility);
        mScrubber.setVisibility(visibility);
 
        if (mPfview != null)
        {
            if (!mPfview.supportsNavigationMode(PFNavigationMode.MOTION))
//              _touchButton.setVisibility(View.GONE);
                Log.d("SimplePlayer", "Not supported nav");
        }
    }
 
    /**
     * Start the video with a local file path
     *
     * @param  filename  The file path on device storage
     */
    public void loadVideo(String filename)
    {
 
        mPfview = PFObjectFactory.view(MainActivity.this);
        mPfasset = PFObjectFactory.assetFromUri(this, Uri.parse(filename), this);
 
        mPfview.displayAsset(mPfasset);
        mPfview.setNavigationMode(mCurrentNavigationMode);
 
        mFrameContainer.addView(mPfview.getView(), 0);
 
    }
 
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
 
    }
 
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        mUpdateThumb = false;
    }
 
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        mPfasset.setPLaybackTime(seekBar.getProgress());
        mUpdateThumb = true;
    }
 
    @Override
    public void onStatusMessage(final PFAsset pfAsset, PFAssetStatus pfAssetStatus) {
 
        switch (pfAssetStatus)
        {
            case LOADED:
                Log.d("SimplePlayer", "Loaded");
                break;
            case DOWNLOADING:
                Log.d("SimplePlayer", "Downloading 360 movie: "+ mPfasset.getDownloadProgress()+" percent complete");
                break;
            case DOWNLOADED:
                Log.d("SimplePlayer", "Downloaded to "+pfAsset.getUrl());
                break;
            case DOWNLOADCANCELLED:
                Log.d("SimplePlayer", "Download cancelled");
                break;
            case PLAYING:
                Log.d("SimplePlayer", "Playing");
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                mScrubber.setEnabled(true);
                mScrubber.setMax((int) pfAsset.getDuration());
                mPlayButton.setText("pause");
                mScrubberMonitorTimer = new Timer();
                final TimerTask task = new TimerTask() {
                    public void run() {
                        if (mUpdateThumb)
                            mScrubber.setProgress((int) pfAsset.getPlaybackTime());
                    }
                };
                mScrubberMonitorTimer.schedule(task, 0, 33);
                break;
            case PAUSED:
                Log.d("SimplePlayer", "Paused");
                mPlayButton.setText("play");
                break;
            case STOPPED:
                Log.d("SimplePlayer", "Stopped");
                mPlayButton.setText("play");
                mScrubberMonitorTimer.cancel();
                mScrubberMonitorTimer = null;
                mScrubber.setProgress(0);
                mScrubber.setEnabled(false);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                break;
            case COMPLETE:
                Log.d("SimplePlayer", "Complete");
                mPlayButton.setText("play");
                mScrubberMonitorTimer.cancel();
                mScrubberMonitorTimer = null;
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                break;
            case ERROR:
                Log.d("SimplePlayer", "Error");
                break;
        }
    }
 
    /**
     * Click listener for the play/pause button
     *
     */
    private View.OnClickListener playListener = new View.OnClickListener() {
        public void onClick(View v) {
            if (mPfasset.getStatus() == PFAssetStatus.PLAYING)
            {
                mPfasset.pause();
            }
            else
                mPfasset.play();
        }
    };
 
    /**
     * Click listener for the stop/back button
     *
     */
    private View.OnClickListener stopListener = new View.OnClickListener() {
        public void onClick(View v) {
            mPfasset.stop();
        }
    };
 
    /**
     * Click listener for the navigation mode (touch/motion (if available))
     *
     */
    private View.OnClickListener touchListener = new View.OnClickListener() {
        public void onClick(View v) {
//          if (mPfview != null)
//          {
 
            Button touchButton = (Button)findViewById(R.id.touchbutton);
            if (mCurrentNavigationMode == PFNavigationMode.TOUCH)
            {
                mCurrentNavigationMode = PFNavigationMode.MOTION;
                touchButton.setText("motion");
            }
            else
            {
                mCurrentNavigationMode = PFNavigationMode.TOUCH;
                touchButton.setText("touch");
            }
            mPfview.setNavigationMode(mCurrentNavigationMode);
        }
//      }
    };
 
    /**
     * Called when pausing the app.
     * This function pauses the playback of the asset when it is playing.
     *
     */
    public void onPause() {
        super.onPause();
        if (mPfasset != null)
        {
            if (mPfasset.getStatus() == PFAssetStatus.PLAYING)
                mPfasset.pause();
        }
    }
 
    public void  onStartCommand(Intent intent, int flags, int startId) {
        mPfasset.play();
    }
 
}

You can download the project here

Video MediaPlayer

We can stream media, including video, to a MediaPlayer object using a surface view.

Video MediaPlayer

For example, you could use the following layout:

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
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
 
    <SurfaceView
        android:id="@+id/activity_video_surfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/activity_video_imageButton_play"/>
 
    <Button
        android:id="@+id/activity_video_imageButton_play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@android:drawable/ic_media_play" />
 
</RelativeLayout>

We will refer to the SurfaceView in the implementation of the Activity class.

Now in our Activity class, add the following interfaces:

1
public class VideoActivity extends Activity implements SurfaceHolder.Callback{

Your IDE should prompt you to add these unimplemented methods:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub
}
 
@Override
public void surfaceCreated(SurfaceHolder arg0) {
//setup
}
 
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub
}
 
@Override
public void onPrepared(MediaPlayer mp) {
//start playback
}

In surfaceCreated we must add these code line:

1
2
3
4
5
6
7
8
9
10
try {
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDisplay(mVidHolder);
    mMediaPlayer.setDataSource(Constants.VID_ADDRESS);
    mMediaPlayer.prepare();
    mMediaPlayer.setOnPreparedListener(this);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
} catch (Exception e) {
    e.printStackTrace();
}

In surfaceDestroyed we add this:

1
mMediaPlayer.stop();

Download code