views:

25

answers:

0

So I'm trying to rick-roll my comp. sci. teacher, but I can't get the video to work. Sound is working perfectly. This is my code so far (code, then XML). Can someone steer me in the right direction?

public class RickRoll extends Activity {
    MediaPlayer rickroll;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        rickroll = MediaPlayer.create(this, R.raw.rickroll);
        SurfaceView view = (SurfaceView) findViewById(R.id.sv);
        view.setMinimumHeight( rickroll.getVideoHeight() );
        view.setMinimumWidth( rickroll.getVideoWidth() );
        rickroll.setDisplay( view.getHolder() );
        try{
            rickroll.prepare();
        }
        catch(Exception e){
        }
    }
    public void rollem(){
        try{
            rickroll.start();
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
    public void clicked(View myView){
        ((TextView) findViewById(R.id.mytext)).setText("MUAHAHAHAHA!!!");
        ((Button) findViewById(R.id.mybutton)).setText("You got Rick Rolled!!!");
        //update button
        rollem();
    }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        >
        <TableRow>
            <TextView  
                android:id="@+id/mytext"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent" 
                android:text="Click the button!"
                />
        </TableRow>
        <TableRow>
            <Button
                android:id="@+id/mybutton"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent" 
                android:text="Click me!"
                android:onClick="clicked"
                />
        </TableRow>
    </TableLayout>
    <SurfaceView
        android:id="@+id/sv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        />
</LinearLayout>

Now, obviously he'd see the big title at the top that said "Rick Roll," but that's beside the point. I'm moving this to another file once I get it working anyways. ;)