1

我正在尝试播放基于videorecordingdemoJDE7.0 示例的视频(代码如下)。

我正在为 OS5.0 构建 - 这就是为什么我不能只运行为 OS7.0 编写的整个演示应用程序。

我正在使用模拟器(9300)并设置了一个文件夹用作我的 sd 卡。我在其中放置了一个 .AVI 视频。我还尝试将 .AVI 放入资源中,然后从那里进行流式传输。

在这两种情况下,当我调用时Player.start(),都会引发以下异常:

  • net.rim.device.internal.media.RimMediaException: 初始化时卸载媒体

我想知道:

  1. 这个错误是什么意思?
  2. 我该如何解决?

或者,播放 .AVI 文件是否有任何真正特殊、严格的要求?


更新:在真正的 Torch 设备上试用了该应用程序,它给了

  • net.rim.device.internal.media.UnloadedMediaException

FWIW 这里是示例代码 - 直接从videorecordingdemo示例应用程序复制。


package mypackage;
/*
 * VideoPlaybackScreen.java
 *
 * Copyright © 1998-2011 Research In Motion Ltd.
 * 
 * Note: For the sake of simplicity, this sample application may not leverage
 * resource bundles and resource strings.  However, it is STRONGLY recommended
 * that application developers make use of the localization features available
 * within the BlackBerry development platform to ensure a seamless application
 * experience across a variety of languages and geographies.  For more information
 * on localizing your application, please refer to the BlackBerry Java Development
 * Environment Development Guide associated with this release.
 */



import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.VideoControl;
import javax.microedition.media.control.VolumeControl;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A screen for playing a video
 */
public class VideoPlaybackScreen extends MainScreen
{
    private Player _videoPlayer;
    private VideoControl _videoControl;

    /**
     * Constructs a screen to playback the video from a specified input stream
     * 
     * @param inputStream The InputStream of the video to display
     * 
     * @throws NullPointerException Thrown if <code>inputStream</code> is null
     */
    public VideoPlaybackScreen(InputStream inputStream)
    {
        if (inputStream == null)
        {
            throw new NullPointerException("'inputStream' cannot be null");
        }

        try
        {  
            _videoPlayer = javax.microedition.media.Manager.createPlayer(inputStream, "video/sbv");
            initScreen();
        }
        catch( Exception e )
        {
            Dialog.alert("Exception while initializing the playback video player\n\n" + e);
        }
    }


    /**
     * Constructs the screen to playback the video from a file
     * 
     * @param file A locator string in URI syntax that points to the video file
     */
    public VideoPlaybackScreen(String file)
    {        
        boolean notEmpty;
        try
        {
            FileConnection fconn = (FileConnection) Connector.open(file);
            notEmpty = fconn.exists() && fconn.fileSize() > 0;
            fconn.close();
        }
        catch( IOException e )
        {
            Dialog.alert("Exception while accessing the video filesize:\n\n" + e);     
            notEmpty = false;           
        }

        // Initialize the player if the video is not empty
        if( notEmpty )
        {
            try
            {
                _videoPlayer = javax.microedition.media.Manager.createPlayer(file);
                initScreen();
            }
            catch( Exception e )
            {
                Dialog.alert("Exception while initializing the playback video player\n\n" + e);  
            }
        }
        else
        {
            add(new LabelField("The video file you are trying to play is empty"));
        }
    }


    /**
     * Initializes the screen after the player has been created
     * 
     * @throws Exception Thrown if an error occurs when initializing the video player, video display or volume control
     */
    private void initScreen() throws Exception
    {
        _videoPlayer.realize();
        _videoPlayer.addPlayerListener(new PlayerListener()
        {
            /**
             * @see javax.microedition.media.PlayerListener#playerUpdate(Player, String, Object)
             */
            public void playerUpdate(Player player, String event, Object eventData)
            {
                // Alert the user and close the screen after the video has
                // finished playing.
                if( event == PlayerListener.END_OF_MEDIA )
                {
                    UiApplication.getUiApplication().invokeLater(new Runnable()
                    {
                        public void run()
                        {
                            Dialog.alert("Finished playing");
                            close();
                        }
                    });
                }
            }
        });

        // Set up the playback
        _videoControl = (VideoControl) _videoPlayer.getControl("VideoControl");
        Field vField = (Field) _videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,
                "net.rim.device.api.ui.Field");
        add(vField);

        VolumeControl vol = (VolumeControl) _videoPlayer.getControl("VolumeControl");
        vol.setLevel(30);
    }


    /**
     * @see net.rim.device.api.ui.Field#onVisibilityChange(boolean)
     */
    protected void onVisibilityChange(boolean visible)
    {
        // If the screen becomes visible and the video player was created, then
        // start the playback.
        if( visible && _videoPlayer != null )
        {
            try
            {
                _videoPlayer.start();
            }
            catch( final Exception e )
            {
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        // If starting the video fails, terminate the playback
                        Dialog.alert("Exception while starting the video\n\n" + e);       
                        close();
                    }
                });
            }
        }
    }


    /**
     * @see net.rim.device.api.ui.Screen#onClose()
     */
    public void close()
    {
        // Close the video player if it was created
        if( _videoPlayer != null )
        {
            _videoPlayer.close();
        }
        super.close();
    }
}
4

0 回答 0