javax.media.CannotRealizeException

解决JMF音频播放问题
本文介绍了一次使用Java Media Framework (JMF)播放音频文件过程中遇到的问题及解决方案。通过调试发现,问题根源在于JMF未正确安装。文章提供了一个简单的示例代码,用于演示如何利用JMF播放本地音频文件。
[quote]今日在测试JMF时,出现了如下错误:经过几番周折原来就是JMF没有安装好。。。[/quote]

public class VedioPlayer {
public static void main(String[] args) {
String path = "E://2.mp3";
VedioPlayer vp = new VedioPlayer();
vp.playVedio(path);
}

/**
* 播放指定音频文件的方法
*
* @param path:要播放的音频文件的路径
*/
public void playVedio(String path) {
File f = new File(path);// 根据音频文件的路径创建File对象
try {
URL url = f.toURI().toURL();// 得到音频文件的URL地址
// 调用管理器创建Player对象的方法
Player player = Manager.createRealizedPlayer(url);
// 加载多媒体音频的数据
player.prefetch();
// 调用播放的方法
player.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
#include <stdio.h> #include <Windows.h> #include <process.h> #include <conio.h> #include "MvCameraControl.h" bool g_bExit = false; // ch:等待按键输入 | en:Wait for key press void WaitForKeyPress(void) { while(!_kbhit()) { Sleep(10); } _getch(); } bool PrintDeviceInfo(MV_CC_DEVICE_INFO* pstMVDevInfo) { if (NULL == pstMVDevInfo) { printf("The Pointer of pstMVDevInfo is NULL!\n"); return false; } if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE) { int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24); int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16); int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8); int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff); // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name printf("CurrentIp: %d.%d.%d.%d\n" , nIp1, nIp2, nIp3, nIp4); printf("UserDefinedName: %s\n\n" , pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName); } else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE) { printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName); printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chSerialNumber); printf("Device Number: %d\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.nDeviceNumber); } else if (pstMVDevInfo->nTLayerType == MV_GENTL_GIGE_DEVICE) { printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName); printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stGigEInfo.chSerialNumber); printf("Model Name: %s\n\n", pstMVDevInfo->SpecialInfo.stGigEInfo.chModelName); } else if (pstMVDevInfo->nTLayerType == MV_GENTL_CAMERALINK_DEVICE) { printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stCMLInfo.chUserDefinedName); printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stCMLInfo.chSerialNumber); printf("Model Name: %s\n\n", pstMVDevInfo->SpecialInfo.stCMLInfo.chModelName); } else if (pstMVDevInfo->nTLayerType == MV_GENTL_CXP_DEVICE) { printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stCXPInfo.chUserDefinedName); printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stCXPInfo.chSerialNumber); printf("Model Name: %s\n\n", pstMVDevInfo->SpecialInfo.stCXPInfo.chModelName); } else if (pstMVDevInfo->nTLayerType == MV_GENTL_XOF_DEVICE) { printf("UserDefinedName: %s\n", pstMVDevInfo->SpecialInfo.stXoFInfo.chUserDefinedName); printf("Serial Number: %s\n", pstMVDevInfo->SpecialInfo.stXoFInfo.chSerialNumber); printf("Model Name: %s\n\n", pstMVDevInfo->SpecialInfo.stXoFInfo.chModelName); } else { printf("Not support.\n"); } return true; } static unsigned int __stdcall WorkThread(void* pUser) { int nRet = MV_OK; MV_FRAME_OUT stImageInfo = {0}; MV_CC_INPUT_FRAME_INFO stInputFrameInfo = {0}; while(1) { nRet = MV_CC_GetImageBuffer(pUser, &stImageInfo, 1000); if (nRet == MV_OK) { printf("Get Image Buffer: Width[%d], Height[%d], FrameNum[%d]\n", stImageInfo.stFrameInfo.nWidth, stImageInfo.stFrameInfo.nHeight, stImageInfo.stFrameInfo.nFrameNum); stInputFrameInfo.pData = stImageInfo.pBufAddr; stInputFrameInfo.nDataLen = stImageInfo.stFrameInfo.nFrameLen; nRet = MV_CC_InputOneFrame(pUser, &stInputFrameInfo); if (MV_OK != nRet) { printf("Input one frame fail! nRet [0x%x]\n", nRet); } nRet = MV_CC_FreeImageBuffer(pUser, &stImageInfo); if(nRet != MV_OK) { printf("Free Image Buffer fail! nRet [0x%x]\n", nRet); } } else { printf("Get Image fail! nRet [0x%x]\n", nRet); } if(g_bExit) { break; } } return 0; } int main() { int nRet = MV_OK; void* handle = NULL; do { // ch:初始化SDK | en:Initialize SDK nRet = MV_CC_Initialize(); if (MV_OK != nRet) { printf("Initialize SDK fail! nRet [0x%x]\n", nRet); break; } // ch:枚举设备 | en:Enum device MV_CC_DEVICE_INFO_LIST stDeviceList; memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST)); nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE | MV_GENTL_CAMERALINK_DEVICE | MV_GENTL_CXP_DEVICE | MV_GENTL_XOF_DEVICE, &stDeviceList); if (MV_OK != nRet) { printf("Enum Devices fail! nRet [0x%x]\n", nRet); break; } if (stDeviceList.nDeviceNum > 0) { for (unsigned int i = 0; i < stDeviceList.nDeviceNum; i++) { printf("[device %d]:\n", i); MV_CC_DEVICE_INFO* pDeviceInfo = stDeviceList.pDeviceInfo[i]; if (NULL == pDeviceInfo) { break; } PrintDeviceInfo(pDeviceInfo); } } else { printf("Find No Devices!\n"); break; } printf("Please Input camera index(0-%d):", stDeviceList.nDeviceNum-1); unsigned int nIndex = 0; scanf_s("%d", &nIndex); if (nIndex >= stDeviceList.nDeviceNum) { printf("Input error!\n"); break; } // ch:选择设备并创建句柄 | en:Select device and create handle nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]); if (MV_OK != nRet) { printf("Create Handle fail! nRet [0x%x]\n", nRet); break; } // ch:打开设备 | en:Open device nRet = MV_CC_OpenDevice(handle); if (MV_OK != nRet) { printf("Open Device fail! nRet [0x%x]\n", nRet); break; } // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera) if (stDeviceList.pDeviceInfo[nIndex]->nTLayerType == MV_GIGE_DEVICE) { int nPacketSize = MV_CC_GetOptimalPacketSize(handle); if (nPacketSize > 0) { nRet = MV_CC_SetIntValueEx(handle,"GevSCPSPacketSize",nPacketSize); if(nRet != MV_OK) { printf("Warning: Set Packet Size fail nRet [0x%x]!", nRet); } } else { printf("Warning: Get Packet Size fail nRet [0x%x]!", nPacketSize); } } // ch:设置触发模式为off | en:Set trigger mode as off nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0); if (MV_OK != nRet) { printf("Set Trigger Mode fail! nRet [0x%x]\n", nRet); break; } // ch:设置HB模式为off | en:Set HB mode as off nRet = MV_CC_SetEnumValue(handle,"ImageCompressionMode", 0); if (MV_OK != nRet) { printf("Get ImageCompressionMode fail! nRet [0x%x]\n", nRet); } MV_CC_RECORD_PARAM stRecordPar; MVCC_INTVALUE stParam = {0}; nRet = MV_CC_GetIntValue(handle, "Width", &stParam); if (MV_OK != nRet) { printf("Get Width fail! nRet [0x%x]\n", nRet); break; } stRecordPar.nWidth = stParam.nCurValue; nRet = MV_CC_GetIntValue(handle, "Height", &stParam); if (MV_OK != nRet) { printf("Get Height fail! nRet [0x%x]\n", nRet); break; } stRecordPar.nHeight = stParam.nCurValue; MVCC_ENUMVALUE stEnumValue = {0}; nRet = MV_CC_GetEnumValue(handle, "PixelFormat", &stEnumValue); if (MV_OK != nRet) { printf("Get Width fail! nRet [0x%x]\n", nRet); break; } stRecordPar.enPixelType = MvGvspPixelType(stEnumValue.nCurValue); MVCC_FLOATVALUE stFloatValue; nRet = MV_CC_GetFloatValue(handle, "ResultingFrameRate", &stFloatValue); if (MV_OK != nRet) { printf("Get Float value fail! nRet [0x%x]\n", nRet); break; } // ch:帧率(大于1/16)fps | en:Frame Rate (>1/16)fps stRecordPar.fFrameRate = stFloatValue.fCurValue; // ch:码率kbps(128kbps-16Mbps) | en:Bitrate kbps(128kbps-16Mbps) stRecordPar.nBitRate = 1000; // ch:录像格式(仅支持AVI) | en:Record Format(AVI is only supported) stRecordPar.enRecordFmtType = MV_FormatType_AVI; stRecordPar.strFilePath= "./Recording.avi"; nRet = MV_CC_StartRecord(handle,&stRecordPar); if (MV_OK != nRet) { printf("Start Record fail! nRet [0x%x]\n", nRet); break; } // ch:开始取流 | en:Start grab image nRet = MV_CC_StartGrabbing(handle); if (MV_OK != nRet) { printf("Start Grabbing fail! nRet [0x%x]\n", nRet); break; } unsigned int nThreadID = 0; void* hThreadHandle = (void*) _beginthreadex( NULL , 0 , WorkThread , handle, 0 , &nThreadID ); if (NULL == hThreadHandle) { printf("Start work thread fail! \n"); break; } printf("Press a key to stop grabbing.\n"); WaitForKeyPress(); g_bExit = true; Sleep(1000); // ch:停止取流 | en:Stop grab image nRet = MV_CC_StopGrabbing(handle); if (MV_OK != nRet) { printf("Stop Grabbing fail! nRet [0x%x]\n", nRet); break; } nRet = MV_CC_StopRecord(handle); if (MV_OK != nRet) { printf("Stop record fail! nRet [0x%x]\n", nRet); break; } // ch:关闭设备 | Close device nRet = MV_CC_CloseDevice(handle); if (MV_OK != nRet) { printf("ClosDevice fail! nRet [0x%x]\n", nRet); break; } // ch:销毁句柄 | Destroy handle nRet = MV_CC_DestroyHandle(handle); if (MV_OK != nRet) { printf("Destroy Handle fail! nRet [0x%x]\n", nRet); break; } handle = NULL; } while (0); if (handle != NULL) { MV_CC_DestroyHandle(handle); handle = NULL; } // ch:反初始化SDK | en:Finalize SDK MV_CC_Finalize(); printf("Press a key to exit.\n"); WaitForKeyPress(); return 0; } 转换成java语言
最新发布
10-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值