Hopefully this is the right place to solicit help.

New to programming in Android but alegdely competent in C and
any assembler.

I have included as much information as possible on the issue I
am having

I am writing an application that allows the user to select a
video to play from a particular areas of a jpeg that occupies
the whole screen. A file is used by the application that defines
whether an area touched has a valid video associated with it
and also tells the app which video to play.

The current code has all the video to play code missing as it
should be easier to debug with a fixed video.

The app runs up to a point. The reading and defining the touch
areas work set_touch_areas();

The touch code works and decodes whether there is a video to
play and which one to play correctly onTouchEvent();

The problem occurs when I try and launch a new activity to
display the video. Iget the message:-

Sorry
The application video_4 (process org.example.
video_4) has stopped unexpectedly. Please try
again.

        Force close.

Now when I look in my book it says if this happens its because
I have not defined my activity in the manifest file. This I
think I have done.

I know the code is not yet complete but I'd have thought it
should at least function as I have tested a simple app to play
from the sdcard and the LocalDisk and this worked fine.

Any help would be gratefully appreciated

A complete copy of my code is copied in below.

If I comment out the startActivity( a ); in onTouchEvent()
the problem does not occur sort of implying the problem is
from there on. I have fiddled around for a couple of days now with no
success


Best regards

Viv a real amateur Android programmer and poor speller

===========
strings.xml
===========
<?xml version="1.0" encoding="utf-8"?>
<resources>
     <string name="app_name">video_4</string>
     <string name="video_play">Video playing</string>
</resources>

====================
video_4 manifest.xml
====================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="org.example.video_4"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/
app_name">
        <activity android:name=".video_4"
                  android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <Activity android:name=".Videos"
                         android:label="@string/video_play"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        </Activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
</manifest>

=========
main.xml
=========
<?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"
    >
        <ImageView
        android:id="@+id/jpgview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>

============
Video_4.java
============
package org.example.video_4;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;

public class video_4 extends Activity {
        byte[] videos_to_play = new byte[960];
        int video_to_play = 8;
        boolean ready = false;

        // Called when the activity is first created
    @Override
    public void onCreate(Bundle savedInstanceState) {

        set_touch_areas();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
        String myJpgPath = /*"/LocalDisk/AdBook/AdBook.JPG"*/"/sdcard/
AdBook/AdBook.JPG";
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;
        Bitmap bm = BitmapFactory.decodeFile( myJpgPath , options);
        jpgView.setImageBitmap(bm);
        ready = true;
    }

    @Override
    public boolean onTouchEvent( MotionEvent event ){
        int xpos,ypos;

        if( event.getAction() != MotionEvent.ACTION_DOWN ){
                return super.onTouchEvent( event );
        }
        xpos = (int)event.getX() / 20;
        ypos = (int)event.getY() / 20;
        if( xpos < 0 || xpos > 39 || ypos < 0 || ypos > 23 || !ready ){
                return true;
        }
        if( videos_to_play[ ( ypos * 40 ) + xpos ] < 8 ){
                video_to_play = videos_to_play[ ( ypos * 40 ) + xpos ];
                Intent a = new Intent( this , Videos.class );
                startActivity( a );
        }
        return true;
    }

    public void set_touch_areas(){
        // read in the touch file
        File file = new File(/*"/LocalDisk/AdBook/adbook.tch"*/"/sdcard/
AdBook/adbook.tch");
        FileInputStream is;
        int c,v,x;

        try {
                is = new FileInputStream(file);
                // Get the size of the file
                long length = file.length();
                if (length != 960 ) {
                        finish();
                }
                // Read in the bytes
                int offset = 0;
                int numRead = 0;
                while (offset < videos_to_play.length &&
(numRead=is.read(videos_to_play, offset, videos_to_play.length-
offset)) >= 0) {
                        offset += numRead;
                }
                // Ensure all the bytes have been read in
                if (offset < videos_to_play.length) {
                        finish();
                }
                } catch (FileNotFoundException e1) {
                        // just bomb if anything is bad with the file read
                        finish();
                } catch (IOException e) {
                        // just bomb if anything is bad with the file read
                        finish();
                }
                // we have read the adbook.tch file so now decode the entries 
based
                // on my algorithm of invert, valid & video_num / random data
                for( c = 0 ; c < 960 ; c++ ){
                        v = ( videos_to_play[ c ] & 0xc0 ) >> 6;                
// mask and align the
bits for checking
                        if( v == 0x02 ){                                        
                        // inverted and video valid
                                x = videos_to_play[c];                          
                // java can only invert integer
                                x = ~x;                                         
                                // so invert an integer, what a pain!!
                                videos_to_play[ c ] = (byte)(x & 0x07);         
// mask to the valid
number
                        } else if( v == 0x01 ){                                 
                // non inverted and video valid
                                videos_to_play[ c ] &= (byte)0x07;              
        // so just isolate the video
number
                        } else {                                                
                                // non valid entry who cares,  I do
                                videos_to_play[ c ] = (byte)0x08;               
        // it's not valid so store the
fact
                        }
                }
    }
}

==========
videos.xml
==========
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <VideoView
        android:id="@+id/vidview"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center"
    />
</FrameLayout>

===========
videos.java
===========
package org.example.video_4;

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

public class Videos extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState){
                super.onCreate(savedInstanceState);
                setContentView( R.layout.videos );
                VideoView video = (VideoView) findViewById( R.id.vidview);
                
video.setVideoPath(/*"/LocalDisk/AdBook/v4.mp4"*/"/sdcard/AdBook/
v4.mp4");
                video.start();
        }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to