[英]Using libmms with Objective-C
我一直在互联网上寻找有关如何使用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;
这不是客观的C,但确实显示了需要传递给mms_connect方法的内容。
所以我创建了一个新项目,包括所有需要的libmms文件并构建它。 编译好了。
下一步是包括
#import "mms.h"
#import "mms_config.h"
并宣布
mms_t *mms = 0;
到目前为止没问题。
我想尝试的下一件事是调用mms_connect方法,这就是我遇到的问题。
我不是C程序员,所以这看起来可能是FUBAR,但这是我最好的尝试。 我不能用
char *g_tcUrl = new char[[strTemp length] + 1];
因为在这里使用的方式不能在目标c中识别新的。 在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代码。 当我尝试测试并弄清楚如何使用libmms时,该代码全部在我的viewDidLoad中。
伙计们,我非常感谢所有建议和帮助,我可以在我的应用程序中使用libmms。
-码
您可以在同一个文件中混合使用C ++和Objective-C。 要么为文件提供.mm扩展名,要么将文件类型更改为sourcecode.cpp.objcpp。
我能想到的最简单的版本:
// 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
的自定义电影播放器或类似内容):
char *myCString = "some data coming from libmms";
NSString *myStringFromACString =
[NSString stringWithCString:myCString
usingEncoding:NSASCIIStringEncoding];
你让事情变得过于复杂。 你不必在这里使用新的。
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);
新的不是C的一部分。它是C ++的一部分,在C中你必须使用malloc在堆上分配内存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.