2 * Copyright 2007 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.j2me;
19 import com.google.zxing.MonochromeBitmapSource;
20 import com.google.zxing.MultiFormatReader;
21 import com.google.zxing.Reader;
22 import com.google.zxing.Result;
24 import javax.microedition.lcdui.Image;
25 import javax.microedition.media.MediaException;
26 import javax.microedition.media.Player;
29 * @author Sean Owen (srowen@google.com)
31 final class SnapshotThread extends Thread {
33 private static SnapshotThread currentThread;
35 private final ZXingMIDlet zXingMIDlet;
37 SnapshotThread(ZXingMIDlet zXingMIDlet) {
38 this.zXingMIDlet = zXingMIDlet;
41 static synchronized void startThread(ZXingMIDlet zXingMIDlet) {
42 if (currentThread == null) {
43 currentThread = new SnapshotThread(zXingMIDlet);
44 currentThread.start();
49 Player player = zXingMIDlet.getPlayer();
51 AdvancedMultimediaManager.setFocus(player);
53 byte[] snapshot = zXingMIDlet.getVideoControl().getSnapshot(null);
54 Image capturedImage = Image.createImage(snapshot, 0, snapshot.length);
55 MonochromeBitmapSource source = new LCDUIImageMonochromeBitmapSource(capturedImage);
56 Reader reader = new MultiFormatReader();
57 Result result = reader.decode(source);
58 zXingMIDlet.handleDecodedText(result.getText());
59 } catch (Throwable t) {
60 zXingMIDlet.showError(t);
64 } catch (MediaException me) {
66 zXingMIDlet.showError(me);