BlackBerry - “初始化时卸载媒体”错误

时间:2012-04-18 16:04:41

标签: blackberry media-player blackberry-simulator

我正在尝试根据JDE7.0中的videorecordingdemo示例播放视频(下面的代码)。

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

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

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

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

我想知道:

  1. 此错误意味着什么?
  2. 如何解决?
  3. 或者对.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();
        }
    }
    

0 个答案:

没有答案