Search in sources :

Example 6 with Media

use of com.codename1.media.Media in project CodenameOne by codenameone.

the class Component method paintComponent.

/**
 * <p>Paints this component as a root by going to all the parent components and
 * setting the absolute translation based on coordinates and scroll status.
 * Restores translation when the painting is finished.<br>
 * One of the uses of this method is to create a "screenshot" as is demonstrated in the code below
 * that creates an image for sharing on social media</p>
 * <script src="https://gist.github.com/codenameone/6bf5e68b329ae59a25e3.js"></script>
 *
 * @param g the graphics to paint this Component on
 * @param background if true paints all parents background
 */
public final void paintComponent(Graphics g, boolean background) {
    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipW = g.getClipWidth();
    int clipH = g.getClipHeight();
    // g.pushClip();
    Container parent = getParent();
    int translateX = 0;
    int translateY = 0;
    while (parent != null) {
        translateX += parent.getX();
        translateY += parent.getY();
        // if (parent.isScrollable()) {
        if (parent.isScrollableX()) {
            translateX -= parent.getScrollX();
        }
        if (parent.isScrollableY()) {
            translateY -= parent.getScrollY();
        }
        // since scrollability can translate everything... we should clip based on the
        // current scroll
        int parentX = parent.getAbsoluteX() + parent.getScrollX();
        if (isRTL()) {
            parentX += parent.getSideGap();
        }
        g.clipRect(parentX, parent.getAbsoluteY() + parent.getScrollY(), parent.getWidth() - parent.getSideGap(), parent.getHeight() - parent.getBottomGap());
        parent = parent.getParent();
    }
    g.clipRect(translateX + getX(), translateY + getY(), getWidth(), getHeight());
    if (background) {
        paintBackgrounds(g);
    }
    g.translate(translateX, translateY);
    paintInternal(g);
    g.translate(-translateX, -translateY);
    paintGlassImpl(g);
    g.setClip(clipX, clipY, clipW, clipH);
// g.popClip();
}
Also used : Point(com.codename1.ui.geom.Point)

Example 7 with Media

use of com.codename1.media.Media in project CodenameOne by codenameone.

the class GameCanvasImplementation method playNativeBuiltinSound.

/**
 * @inheritDoc
 */
protected void playNativeBuiltinSound(Object data) {
    try {
        try {
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
            m.play();
        } catch (Exception err) {
            // some simulators take issue with the audio/mpeg string but the mp3 string
            // works fine
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
            m.play();
        }
    } catch (IOException ex) {
        // not likely since the stream is a byte array input stream
        ex.printStackTrace();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Media(com.codename1.media.Media) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Example 8 with Media

use of com.codename1.media.Media in project CodenameOne by codenameone.

the class BlackBerryImplementation method playNativeBuiltinSound.

/**
 * @inheritDoc
 */
protected void playNativeBuiltinSound(Object data) {
    try {
        try {
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
            m.play();
        } catch (Exception err) {
            // some simulators take issue with the audio/mpeg string but the mp3 string
            // works fine
            Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
            m.play();
        }
    } catch (IOException ex) {
        // not likely since the stream is a byte array input stream
        ex.printStackTrace();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Media(com.codename1.media.Media) IOException(java.io.IOException) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Aggregations

Media (com.codename1.media.Media)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 Paint (android.graphics.Paint)2 MediaPlayer (android.media.MediaPlayer)2 Audio (com.codename1.media.Audio)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 RandomAccessFile (java.io.RandomAccessFile)2 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)2 MediaException (javax.microedition.media.MediaException)2 RecordStoreException (javax.microedition.rms.RecordStoreException)2 IBinder (android.os.IBinder)1 BufferedOutputStream (com.codename1.io.BufferedOutputStream)1 TarInputStream (com.codename1.io.tar.TarInputStream)1 AudioService (com.codename1.media.AudioService)1 MediaProxy (com.codename1.media.MediaProxy)1 Dialog (com.codename1.ui.Dialog)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 Point (com.codename1.ui.geom.Point)1