我已经在互联网上找了几天关于如何使用libmms的教程或例子。似乎没有,这对于一个似乎被广泛使用的lib来说很奇怪。
LibMMS是一个用于解析mms://和mmsh://类型网络流的通用库。http://sourceforge.net/projects/libmms/files/libmms/0.6.2/libmms-0.6.2.tar.gz/download
我发现的唯一代码样本来自stackoverflow上的另一篇文章。
如下所示。
mms_connect(NULL, NULL, g_tcUrl.av_val, g_hostname.av_val, g_playpath.av_val, "", g_port, 128*1024)注意:
NSString* strTemp;
strTemp = @"mms://123.30.49.85/htv2";
// strTemp = @"mms://212.58.251.92/wms/bbc_ami/radio1/radio1_bb_live_int_eq1_sl0";
g_tcUrl.av_val = new char[[strTemp length] + 1];
[strTemp getCString:g_tcUrl.av_val
maxLength:([strTemp length]+1)
encoding:NSUTF8StringEncoding];
g_tcUrl.av_len = strlen(g_tcUrl.av_val);
//strTemp = @"212.58.251.92";
strTemp = @"123.30.49.85";
g_hostname.av_val = new char[[strTemp length]+1];
[strTemp getCString:g_hostname.av_val
maxLength:([strTemp length]+1)
encoding:NSUTF8StringEncoding];
g_hostname.av_len = strlen(g_hostname.av_val);
//strTemp = @"/wms/bbc_ami/radio1/radio1_bb_live_int_eq1_sl0";
strTemp = @"/htv2";
g_playpath.av_val = new char[[strTemp length] + 1];
[strTemp getCString:g_playpath.av_val
maxLength:([strTemp length]+1)
encoding:NSUTF8StringEncoding];
g_playpath.av_len = strlen(g_playpath.av_val);
g_port = 1755; 这不是objective C,但显示了需要传递到mms_connect方法中的内容。
所以我创建了一个新项目,包含了所有需要的libmms文件并构建了它。编译正常。
下一步是包含
#import "mms.h"
#import "mms_config.h"并声明
mms_t *mms = 0;到目前为止还没有问题。
我想要尝试的下一件事是调用mms_connect方法,这就是我被卡住的地方。
我不是一个C程序员,所以这可能看起来很混乱,但这是我最好的尝试。我不能使用
char *g_tcUrl = new char[[strTemp length] + 1];因为在目标c中没有以这里使用的方式识别new。在Objective-C中,我应该使用什么来达到同样的效果?
mms_t *mms = 0;
NSString* strTemp;
strTemp = @"mms://123.30.49.85/htv2";
char *g_tcUrl = new char[[strTemp length] + 1];
[strTemp getCString:g_tcUrl maxLength:([strTemp length]+1)
encoding:NSUTF8StringEncoding];
strTemp = @"123.30.49.85";
char *g_hostname = new char[[strTemp length]+1];
[strTemp getCString:g_hostname maxLength:([strTemp length]+1)
encoding:NSUTF8StringEncoding];
strTemp = @"/htv2";
char * g_playpath = new char[[strTemp length] + 1];
[strTemp getCString:g_playpath maxLength:([strTemp length]+1)
encoding:NSUTF8StringEncoding];
int g_port = 1755;
//mms = mms_connect(mms_io_t *io, void *data, const char *url, const char *host,
const char *uri, const char *query, int port, int bandwidth);
mms = mms_connect(NULL, NULL, g_tcUrl, g_hostname, g_playpath, "", g_port,
128*1024);现在,我尝试在objective-c文件中混入C代码。当我尝试测试并弄清楚如何使用libmm时,这些代码都在我的viewDidLoad中。
伙计们,我很感谢你们能提供的建议和帮助,让libmms在我的应用程序中工作。
-Code
发布于 2011-06-08 15:38:31
我能想到的最简单的版本:
// wherever these NSStrings come from in the app, we can use them
NSString *mmsURL = @"mms://123.30.49.85/htv2",
*mmsHostname = @"123.30.49.85",
*mmsPath = @"/htv2";
NSInteger port = 1755;
mms_t *mms = mms_connect(NULL, NULL,
[mmsURL cStringUsingEncoding:NSASCIIStringEncoding],
[mmsHostname cStringUsingEncoding:NSASCIIStringEncoding],
[mmsPath cStringUsingEncoding:NSASCIIStringEncoding],
"", port, 128*1024);要使数据也以另一种方式移动(如果要将流数据传递到自定义AVPlayer-based电影播放器或类似播放器中):
char *myCString = "some data coming from libmms";
NSString *myStringFromACString =
[NSString stringWithCString:myCString
usingEncoding:NSASCIIStringEncoding];发布于 2011-06-02 00:19:12
您可以在同一文件中混合使用C++和Objective-C。可以为文件指定.mm扩展名,也可以将文件类型更改为sourcecode.cpp.objcpp。
发布于 2011-06-08 15:16:35
你把事情搞得太复杂了。您不需要在这里使用new。
mms_t *mms = 0;
const char* g_tcUrl = "mms://123.30.49.85/htv2"; // Easy C String,
// No need for heap allocation.
const char* g_hostname = "123.30.49.85";
const char* g_playpath = "/htv2";
int g_port = 1755;
//mms = mms_connect(mms_io_t *io, void *data, const char *url, const char *host, const char *uri, const char *query, int port, int bandwidth);
mms = mms_connect(NULL, NULL, g_tcUrl, g_hostname, g_playpath, "", g_port,
128*1024);另外,new不是C的一部分,它是C++的一部分,在C中,你必须使用malloc在堆上分配内存。
https://stackoverflow.com/questions/5634038
复制相似问题