我想奏出基于视频videorecordingdemo
样品从JDE7.0(下面的代码)。
我建立了OS5.0 - 这就是为什么我不能只是运行,这是为OS7.0写整个演示应用程序。
我使用的是仿真器(9300),并建立了一个文件夹,用作我的SD卡。 我已经把一个.AVI视频在那里。 我也曾尝试放置.AVI到资源,并从那里流式传输。
在这两种情况下,当我打电话Player.start()
下面的异常被抛出:
-
net.rim.device.internal.media.RimMediaException
:媒体在初始化卸载
我想知道:
- 这个错误是什么意思?
- 我怎样才能解决这个问题?
或者是任何真正特殊,为.AVI文件的播放要求严格?
更新:尝试一个真正的火炬设备上的应用程序,它给了
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();
}
}