09.02.2013 Views

Sviluppo di una piattaforma per lo streaming multimediale - MobiLab ...

Sviluppo di una piattaforma per lo streaming multimediale - MobiLab ...

Sviluppo di una piattaforma per lo streaming multimediale - MobiLab ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[…] Omissis […] // import delle classi necessarie<br />

<strong>Sviluppo</strong> <strong>di</strong> <strong>una</strong> <strong>piattaforma</strong> <strong>per</strong> <strong>lo</strong> <strong>streaming</strong> multime<strong>di</strong>ale in ambiente Android<br />

public class playerActivity extends Activity implements OnErrorListener,<br />

OnBufferingUpdateListener, OnCompletionListener,<br />

Me<strong>di</strong>aPlayer.OnPreparedListener, SurfaceHolder.Callback {<br />

private static final String TAG = "playerActivity";<br />

private Me<strong>di</strong>aPlayer mp;<br />

private SurfaceView mPreview;<br />

private E<strong>di</strong>tText mPath;<br />

private SurfaceHolder holder;<br />

private ImageButton mPlay;<br />

private ImageButton mPause;<br />

private ImageButton mReset;<br />

private ImageButton mStop;<br />

private String current;<br />

public void onCreate(Bundle icicle) {<br />

su<strong>per</strong>.onCreate(icicle);<br />

setContentView(R.layout.main);<br />

// Pulsanti<br />

mPreview = (SurfaceView) findViewById(R.id.surface);<br />

mPath = (E<strong>di</strong>tText) findViewById(R.id.path);<br />

mPlay = (ImageButton) findViewById(R.id.play);<br />

mPause = (ImageButton) findViewById(R.id.pause);<br />

mReset = (ImageButton) findViewById(R.id.reset);<br />

mStop = (ImageButton) findViewById(R.id.stop);<br />

[…] Omissis […] // listener dei pulsanti<br />

}<br />

getWindow().setFormat(PixelFormat.TRANSPARENT);<br />

// <strong>di</strong>mensione<br />

holder = mPreview.getHolder();<br />

holder.addCallback(this);<br />

holder.setFixedSize(400, 300);<br />

private void playVideo() {<br />

try {<br />

final String path = mPath.getText().toString();<br />

Log.v(TAG, "path: " + path);<br />

if (path.equals(current) && mp != null) {<br />

mp.start();<br />

return;<br />

}<br />

current = path;<br />

// creazione<br />

mp = new Me<strong>di</strong>aPlayer();<br />

mp.setOnErrorListener(this);<br />

mp.setOnBufferingUpdateListener(this);<br />

mp.setOnCompletionListener(this);<br />

mp.setOnPreparedListener(this);<br />

79

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!